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 27, 2024
1 parent c651007 commit b2494d9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@ public static function get_one($callerClass = null, $filter = "", $cache = true,
*
* Also flush the cached results for all relations (has_one, has_many, many_many)
*
* @param bool $persistent When true will also clear persistent data stored in the Cache system.
* @param boolean $persistent When true will also clear persistent data stored in the Cache system.
* When false will just clear session-local cached data
*/
public function flushCache(bool $persistent = true): static
Expand Down
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 b2494d9

Please sign in to comment.