Skip to content

Commit

Permalink
API Move logic from silverstripe/cms into central place
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 28, 2024
1 parent c651007 commit d5f58e1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
35 changes: 35 additions & 0 deletions src/ORM/Hierarchy/Hierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 0 additions & 10 deletions src/Security/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
14 changes: 14 additions & 0 deletions src/Security/PermissionCheckable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace SilverStripe\Security;

/**
* Model with permissions that can be checked using PermissionChecker
*/
interface PermissionCheckable
{
/**
* Get the permission checker for this model
*/
public function getPermissionChecker(): PermissionChecker;
}

0 comments on commit d5f58e1

Please sign in to comment.