From 0e63edb37551244b9056d75bcf5b1b0a045bf374 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Thu, 17 Jun 2021 10:05:21 +0200 Subject: [PATCH] Update IContentTypeBase to use group names as property groups (no parent/level 1) for backwards compatibility --- src/Umbraco.Core/Models/ContentTypeBase.cs | 6 +++--- src/Umbraco.Core/Models/ContentTypeCompositionBase.cs | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index 4865db428a..5bff936652 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -348,7 +348,7 @@ namespace Umbraco.Core.Models // get new group, if required, and ensure it exists var newPropertyGroup = propertyGroupName == null ? null - : PropertyGroups.FirstOrDefault(x => x.Name == propertyGroupName); + : PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals(propertyGroupName) && x.ParentKey == null && x.Level == 1); if (propertyGroupName != null && newPropertyGroup == null) return false; // get old group @@ -403,11 +403,11 @@ namespace Umbraco.Core.Models public void RemovePropertyGroup(string propertyGroupName) { // if no group exists with that name, do nothing - var group = PropertyGroups[propertyGroupName]; + var group = PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals(propertyGroupName) && x.ParentKey == null && x.Level == 1); if (group == null) return; // first remove the group - PropertyGroups.RemoveItem(propertyGroupName); + PropertyGroups.Remove(group); // Then re-assign the group's properties to no group foreach (var property in group.PropertyTypes) diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index ff61a15979..514b307396 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -218,7 +218,7 @@ namespace Umbraco.Core.Models private PropertyGroup AddAndReturnPropertyGroup(string name) { // ensure we don't have it already - if (PropertyGroups.Any(x => x.Name == name)) + if (PropertyGroups.Any(x => x.Name.InvariantEquals(name) && x.ParentKey == null && x.Level == 1)) return null; // create the new group @@ -227,7 +227,7 @@ namespace Umbraco.Core.Models // check if it is inherited - there might be more than 1 but we want the 1st, to // reuse its sort order - if there are more than 1 and they have different sort // orders... there isn't much we can do anyways - var inheritGroup = CompositionPropertyGroups.FirstOrDefault(x => x.Name == name); + var inheritGroup = CompositionPropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals(name) && x.ParentKey == null && x.Level == 1); if (inheritGroup == null) { // no, just local, set sort order @@ -260,9 +260,8 @@ namespace Umbraco.Core.Models return false; // get and ensure a group local to this content type - var group = PropertyGroups.Contains(propertyGroupName) - ? PropertyGroups[propertyGroupName] - : AddAndReturnPropertyGroup(propertyGroupName); + var group = PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals(propertyGroupName) && x.ParentKey == null && x.Level == 1) + ??AddAndReturnPropertyGroup(propertyGroupName); if (group == null) return false;