Skip to content

Commit 41b7696

Browse files
authored
Make invariant variant merge for blocks capable of detecting sub layouts (#18234)
1 parent 6249ac9 commit 41b7696

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

Diff for: src/Umbraco.Core/Models/Blocks/BlockGridLayoutAreaItem.cs

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ public BlockGridLayoutAreaItem()
1111

1212
public BlockGridLayoutAreaItem(Guid key)
1313
=> Key = key;
14+
15+
public bool ContainsContent(Guid key)
16+
=> Items.Any(item => item.ReferencesContent(key));
17+
18+
public bool ContainsSetting(Guid key)
19+
=> Items.Any(item => item.ReferencesSetting(key));
1420
}

Diff for: src/Umbraco.Core/Models/Blocks/BlockGridLayoutItem.cs

+6
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ public BlockGridLayoutItem(Guid contentKey, Guid settingsKey)
3838
: base(contentKey, settingsKey)
3939
{
4040
}
41+
42+
public override bool ReferencesContent(Guid key)
43+
=> ContentKey == key || Areas.Any(area => area.ContainsContent(key));
44+
45+
public override bool ReferencesSetting(Guid key)
46+
=> SettingsKey == key || Areas.Any(area => area.ContainsSetting(key));
4147
}

Diff for: src/Umbraco.Core/Models/Blocks/BlockLayoutItemBase.cs

+6
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ protected BlockLayoutItemBase(Guid contentKey, Guid settingsKey)
8181
SettingsKey = settingsKey;
8282
SettingsUdi = new GuidUdi(Constants.UdiEntityType.Element, settingsKey);
8383
}
84+
85+
public virtual bool ReferencesContent(Guid key)
86+
=> ContentKey == key;
87+
88+
public virtual bool ReferencesSetting(Guid key)
89+
=> SettingsKey == key;
8490
}

Diff for: src/Umbraco.Core/Models/Blocks/IBlockLayoutItem.cs

+4
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ public interface IBlockLayoutItem
1414
public Guid ContentKey { get; set; }
1515

1616
public Guid? SettingsKey { get; set; }
17+
18+
public bool ReferencesContent(Guid key) => ContentKey == key;
19+
20+
public bool ReferencesSetting(Guid key) => SettingsKey == key;
1721
}

Diff for: src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyValueEditorBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ private void MapBlockItemDataFromEditor(List<BlockItemData> items)
320320

321321
// remove all the blocks that are no longer part of the layout
322322
target.BlockValue.ContentData.RemoveAll(contentBlock =>
323-
target.Layout!.Any(layoutItem => layoutItem.ContentKey == contentBlock.Key) is false);
323+
target.Layout!.Any(layoutItem => layoutItem.ReferencesContent(contentBlock.Key)) is false);
324324

325325
target.BlockValue.SettingsData.RemoveAll(settingsBlock =>
326-
target.Layout!.Any(layoutItem => layoutItem.SettingsKey == settingsBlock.Key) is false);
326+
target.Layout!.Any(layoutItem => layoutItem.ReferencesSetting(settingsBlock.Key)) is false);
327327

328328
CleanupVariantValues(source.BlockValue.ContentData, target.BlockValue.ContentData, canUpdateInvariantData, allowedCultures);
329329
CleanupVariantValues(source.BlockValue.SettingsData, target.BlockValue.SettingsData, canUpdateInvariantData, allowedCultures);

0 commit comments

Comments
 (0)