diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index 59d9d4dd11..c3d7451452 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -140,10 +140,21 @@ namespace Umbraco.Core.Models } } - internal static class PropertyGroupExtensions + public static class PropertyGroupExtensions { private const char aliasSeparator = '/'; + internal static string GetCurrentAlias(string alias) + { + var lastIndex = alias?.LastIndexOf(aliasSeparator) ?? -1; + if (lastIndex != -1) + { + return alias.Substring(lastIndex + 1); + } + + return alias; + } + internal static string GetParentAlias(string alias) { var lastIndex = alias?.LastIndexOf(aliasSeparator) ?? -1; @@ -155,26 +166,57 @@ namespace Umbraco.Core.Models return alias.Substring(0, lastIndex); } - public static string GetParentAlias(this PropertyGroup propertyGroup) => GetParentAlias(propertyGroup.Alias); + /// + /// Gets the current alias. + /// + /// The property group. + /// + /// The current alias. + /// + public static string GetCurrentAlias(this PropertyGroup propertyGroup) => GetCurrentAlias(propertyGroup.Alias); - public static void UpdateParentAlias(this PropertyGroup propertyGroup, string parentAlias) + /// + /// Updates the current alias. + /// + /// The property group. + /// The current alias. + public static void UpdateCurrentAlias(this PropertyGroup propertyGroup, string currentAlias) { - // Get current alias without parent - var alias = propertyGroup.Alias; - var lastIndex = alias?.LastIndexOf(aliasSeparator) ?? -1; - if (lastIndex != -1) - { - alias = alias.Substring(lastIndex + 1); - } - - // Update alias + var parentAlias = propertyGroup.GetParentAlias(); if (string.IsNullOrEmpty(parentAlias)) { - propertyGroup.Alias = alias; + propertyGroup.Alias = currentAlias; } else { - propertyGroup.Alias = parentAlias + aliasSeparator + alias; + propertyGroup.Alias = parentAlias + aliasSeparator + currentAlias; + } + } + + /// + /// Gets the parent alias. + /// + /// The property group. + /// + /// The parent alias. + /// + public static string GetParentAlias(this PropertyGroup propertyGroup) => GetParentAlias(propertyGroup.Alias); + + /// + /// Updates the parent alias. + /// + /// The property group. + /// The parent alias. + public static void UpdateParentAlias(this PropertyGroup propertyGroup, string parentAlias) + { + var currentAlias = propertyGroup.GetCurrentAlias(); + if (string.IsNullOrEmpty(parentAlias)) + { + propertyGroup.Alias = currentAlias; + } + else + { + propertyGroup.Alias = parentAlias + aliasSeparator + currentAlias; } }