Skip to content

Commit eb4acba

Browse files
bjarnefelit0451
andauthored
Set default tree group for core trees (#11801)
Co-authored-by: Elitsa Marinovska <[email protected]>
1 parent d5ba5be commit eb4acba

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Umbraco.Core/Extensions/TypeExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,16 @@ public static IEnumerable<T> GetCustomAttributes<T>(this Type type, bool inherit
430430
where T : Attribute
431431
{
432432
if (type == null) return Enumerable.Empty<T>();
433-
return type.GetCustomAttributes(typeof (T), inherited).OfType<T>();
433+
return type.GetCustomAttributes(typeof(T), inherited).OfType<T>();
434434
}
435435

436-
/// <summary>
436+
public static bool HasCustomAttribute<T>(this Type type, bool inherit)
437+
where T : Attribute
438+
{
439+
return type.GetCustomAttribute<T>(inherit) != null;
440+
}
441+
442+
/// <summary>
437443
/// Tries to return a value based on a property name for an object but ignores case sensitivity
438444
/// </summary>
439445
/// <param name="type"></param>

src/Umbraco.Web.BackOffice/Trees/TreeCollectionBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public void AddTreeController(Type controllerType)
4848

4949
var attribute = controllerType.GetCustomAttribute<TreeAttribute>(false);
5050
if (attribute == null) return;
51+
52+
bool isCoreTree = controllerType.HasCustomAttribute<CoreTreeAttribute>(false);
53+
54+
// Use section as tree group if core tree, so it isn't grouped by empty key and thus end up in "Third Party" tree group if adding custom tree nodes in other groups, e.g. "Settings" tree group.
55+
attribute.TreeGroup = attribute.TreeGroup ?? (isCoreTree ? attribute.SectionAlias : attribute.TreeGroup);
56+
5157
var tree = new Tree(attribute.SortOrder, attribute.SectionAlias, attribute.TreeGroup, attribute.TreeAlias, attribute.TreeTitle, attribute.TreeUse, controllerType, attribute.IsSingleNodeTree);
5258
_trees.Add(tree);
5359
}

0 commit comments

Comments
 (0)