Ensure groups are grouped on name, parent key and type when mapped

This commit is contained in:
Ronald Barendse
2021-06-22 13:21:16 +02:00
parent 2560804493
commit a5c3847937
2 changed files with 28 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
{
/// <summary>
/// A group of property types, which corresponds to the properties grouped under a Tab.
/// Represents a group of property types.
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
@@ -40,6 +40,9 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or sets the parent key of the group.
/// </summary>
/// <value>
/// The parent key.
/// </value>
[DataMember]
public Guid? ParentKey
{
@@ -48,8 +51,11 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Gets or sets the Sort Order of the Group
/// Gets or sets the type of the group.
/// </summary>
/// <value>
/// The type.
/// </value>
[DataMember]
public PropertyGroupType Type
{
@@ -58,8 +64,11 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Gets or sets the Name of the Group, which corresponds to the Tab-name in the UI
/// Gets or sets the name of the group.
/// </summary>
/// <value>
/// The name.
/// </value>
[DataMember]
public string Name
{
@@ -70,6 +79,9 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or sets the icon of the group.
/// </summary>
/// <value>
/// The icon.
/// </value>
[DataMember]
public string Icon
{
@@ -78,8 +90,11 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Gets or sets the Sort Order of the Group
/// Gets or sets the sort order of the group.
/// </summary>
/// <value>
/// The sort order.
/// </value>
[DataMember]
public int SortOrder
{
@@ -88,10 +103,13 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Gets or sets a collection of PropertyTypes for this PropertyGroup
/// Gets or sets a collection of property types for the group.
/// </summary>
/// <value>
/// The property types.
/// </value>
/// <remarks>
/// Marked DoNotClone because we will manually deal with cloning and the event handlers
/// Marked with DoNotClone, because we will manually deal with cloning and the event handlers.
/// </remarks>
[DataMember]
[DoNotClone]
@@ -117,9 +135,9 @@ namespace Umbraco.Core.Models
}
}
public bool Equals(PropertyGroup other) => other != null && base.Equals(other) && ParentKey == other.ParentKey && Type == other.Type && Icon == other.Icon && Name.InvariantEquals(other.Name);
public bool Equals(PropertyGroup other) => base.Equals(other) && Name.InvariantEquals(other.Name);
public override int GetHashCode() => (base.GetHashCode(), ParentKey, Type, Icon, Name?.ToLowerInvariant()).GetHashCode();
public override int GetHashCode() => base.GetHashCode() ^ (Name?.ToLowerInvariant()).GetHashCode();
protected override void PerformDeepClone(object clone)
{

View File

@@ -129,9 +129,9 @@ namespace Umbraco.Web.Models.Mapping
// need to aggregate the tabs, as content.PropertyGroups contains all the composition tabs,
// and there might be duplicates (content does not work like contentType and there is no
// content.CompositionPropertyGroups).
var groups = contentType.CompositionPropertyGroups.ToArray();
var groups = contentType.CompositionPropertyGroups.OrderByHierarchy().ToArray();
var parentKeys = groups.Where(x => x.ParentKey.HasValue).Select(x => x.ParentKey.Value).Distinct().ToArray();
foreach (var groupsByHierarchy in groups.OrderByHierarchy().GroupBy(x => (x.Name, x.ParentKey)))
foreach (var groupsByHierarchy in groups.GroupBy(x => (x.Name, x.ParentKey, x.Type)))
{
var properties = new List<Property>();