diff --git a/src/ORM/Hierarchy/Hierarchy.php b/src/ORM/Hierarchy/Hierarchy.php index 4ae4014668d..07d60ac54fd 100644 --- a/src/ORM/Hierarchy/Hierarchy.php +++ b/src/ORM/Hierarchy/Hierarchy.php @@ -617,6 +617,30 @@ public function showingCMSTree() && in_array($controller->getAction(), ["treeview", "listview", "getsubtree"]); } + /** + * Return the CSS classes to apply to this node in the CMS tree. + */ + public function CMSTreeClasses(): string + { + $owner = $this->getOwner(); + $classes = sprintf('class-%s', Convert::raw2htmlid(get_class($owner))); + + if (!$owner->canAddChildren()) { + $classes .= " nochildren"; + } + + if (!$owner->canEdit() && !$owner->canAddChildren()) { + if (!$owner->canView()) { + $classes .= " disabled"; + } else { + $classes .= " edit-disabled"; + } + } + + $owner->invokeWithExtensions('updateCMSTreeClasses', $classes); + return $classes; + } + /** * Find the first class in the inheritance chain that has Hierarchy extension applied * @@ -777,6 +801,17 @@ public function getBreadcrumbs($separator = ' » ') return implode($separator ?? '', $crumbs); } + /** + * Get the title that will be used in TreeDropdownField and other tree structures. + */ + public function getTreeTitle(): string + { + $owner = $this->getOwner(); + $title = $owner->MenuTitle ?: $owner->Title; + $owner->extend('updateTreeTitle', $title); + return $title ?? ''; // @TODO see if we need to escape this (it was escaped in Group and is in File too) + } + /** * Get the name of the dedicated sort field, if there is one. */ diff --git a/src/Security/Group.php b/src/Security/Group.php index 6c10d32c073..3cc484dead4 100755 --- a/src/Security/Group.php +++ b/src/Security/Group.php @@ -494,16 +494,6 @@ public function stageChildren() ->sort('"Sort"'); } - /** - * @return string - */ - public function getTreeTitle() - { - $title = htmlspecialchars($this->Title ?? '', ENT_QUOTES); - $this->extend('updateTreeTitle', $title); - return $title; - } - /** * Overloaded to ensure the code is always descent. * diff --git a/src/Security/PermissionCheckable.php b/src/Security/PermissionCheckable.php new file mode 100644 index 00000000000..1e5348f53a2 --- /dev/null +++ b/src/Security/PermissionCheckable.php @@ -0,0 +1,14 @@ +