Skip to content

Commit 4698be3

Browse files
KevinJumpCopilot
andauthored
V17/rte block import fix (#850)
* Umbraco RC2 - Packag Update * re-ordered converters incase this is an issue. * Added more block level mapping to capture the change in the block format inside a RTE Block. * update client rc2 * Update uSync.Core/Mapping/Mappers/RTEMappers/RTEBlockDataContentMigrator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b2fbcab commit 4698be3

5 files changed

Lines changed: 61 additions & 10 deletions

File tree

uSync.Backoffice.Management.Client/usync-assets/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

uSync.Backoffice.Management.Client/usync-assets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@hey-api/client-fetch": "^0.10.0",
5959
"@hey-api/openapi-ts": "^0.85.0",
6060
"@microsoft/signalr": "^9.0.6",
61-
"@umbraco-cms/backoffice": "^17.0.0-rc1",
61+
"@umbraco-cms/backoffice": "^17.0.0-rc2",
6262
"lit": "^3.2.1",
6363
"prettier": "^3.6.2",
6464
"typescript": "^5.9.3",

uSync.Core/Extensions/JsonTextExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public static class JsonTextExtensions
2525
Converters =
2626
{
2727
new JsonStringEnumConverter(),
28-
new JsonObjectConverter(),
29-
new JsonBlockValueConverter(),
3028
new JsonUdiConverter(),
3129
new JsonUdiRangeConverter(),
30+
new JsonObjectConverter(),
31+
new JsonBlockValueConverter(),
32+
3233
new JsonBooleanConverter(),
3334
new JsonXElementConverter(),
3435
// new JsonBlockListLayoutItemConverter(),

uSync.Core/Mapping/Mappers/RTEMappers/RTEBlockDataContentMigrator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public RTEBlockDataContentMigrator(
4343
/// <inheritdoc />
4444
public override async Task<string?> GetImportValueAsync(string value, string editorAlias)
4545
{
46+
// Workaround: The nested block layout values won't load if the editor alias is still "Umbraco.TinyMCE".
47+
// Expected behavior: The editor should support loading nested block layouts regardless of the alias.
48+
// This might be a bug in Umbraco core. As of [2024-06-XX], this issue has/has not been reported to the Umbraco core team.
49+
// (If reported, add link: https://github.com/umbraco/Umbraco-CMS/issues/XXXX)
50+
// Remove this workaround if/when the core issue is fixed.
51+
value = value.Replace("\"Umbraco.TinyMCE\":", $"\"{editorAlias}\":");
52+
4653
if (value.TryDeserialize<RichTextEditorValue>(out RichTextEditorValue? richTextEditorValue) is false || richTextEditorValue is null)
4754
return await base.GetImportValueAsync(value, editorAlias);
4855

uSync.Core/Mapping/SyncBlockMapperBase.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using System.Collections;
44
using System.Text.Json.Nodes;
5-
5+
using Umbraco.Cms.Core;
66
using Umbraco.Cms.Core.Models;
77
using Umbraco.Cms.Core.Models.Blocks;
88
using Umbraco.Cms.Core.Services;
@@ -79,6 +79,8 @@ public SyncBlockMapperBase(
7979

8080
foreach (var contentItem in blocks)
8181
{
82+
MigrateBlock(contentItem);
83+
8284
await ProcessBlockData(contentItem, GetValueMethod);
8385
}
8486

@@ -109,6 +111,47 @@ private async Task ProcessBlockData(BlockItemData? blockItem, Func<object?, stri
109111
}
110112
}
111113

114+
#pragma warning disable CS0618 // Type or member is obsolete (post v18, we will need to have our own model?)
115+
private bool MigrateBlock(BlockItemData? block)
116+
{
117+
if (block is null) return false;
118+
119+
bool converted = false;
120+
if (block.Values.Count == 0 && block.RawPropertyValues?.Count > 0)
121+
{
122+
block.Values = SyncBlockMapperBase<TBlockValue>.MigrateBlockRawValues(block.RawPropertyValues);
123+
block.RawPropertyValues.Clear();
124+
converted = true;
125+
}
126+
127+
if (block.Key == Guid.Empty && block.Udi is GuidUdi guidUdi)
128+
{
129+
block.Key = guidUdi.Guid;
130+
converted = true;
131+
}
132+
133+
block.Udi = null;
134+
135+
return converted;
136+
}
137+
#pragma warning restore CS0618 // Type or member is obsolete
138+
139+
140+
private static List<BlockPropertyValue> MigrateBlockRawValues(Dictionary<string, object?> rawValues)
141+
{
142+
var values = new List<BlockPropertyValue>();
143+
foreach (var kvp in rawValues)
144+
{
145+
values.Add(new BlockPropertyValue
146+
{
147+
Alias = kvp.Key,
148+
Value = kvp.Value
149+
});
150+
}
151+
return values;
152+
}
153+
154+
112155
private async Task<IContentType?> GetContentType(Guid contentTypeKey)
113156
=> await _contentTypeService.GetAsync(contentTypeKey);
114157

0 commit comments

Comments
 (0)