Skip to content

Commit 692d9d9

Browse files
committed
API Move logic from silverstripe/cms into central place
1 parent c651007 commit 692d9d9

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

src/ORM/DataObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ public static function get_one($callerClass = null, $filter = "", $cache = true,
35443544
*
35453545
* Also flush the cached results for all relations (has_one, has_many, many_many)
35463546
*
3547-
* @param bool $persistent When true will also clear persistent data stored in the Cache system.
3547+
* @param boolean $persistent When true will also clear persistent data stored in the Cache system.
35483548
* When false will just clear session-local cached data
35493549
*/
35503550
public function flushCache(bool $persistent = true): static

src/ORM/Hierarchy/Hierarchy.php

+35
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,30 @@ public function showingCMSTree()
617617
&& in_array($controller->getAction(), ["treeview", "listview", "getsubtree"]);
618618
}
619619

620+
/**
621+
* Return the CSS classes to apply to this node in the CMS tree.
622+
*/
623+
public function CMSTreeClasses(): string
624+
{
625+
$owner = $this->getOwner();
626+
$classes = sprintf('class-%s', Convert::raw2htmlid(get_class($owner)));
627+
628+
if (!$owner->canAddChildren()) {
629+
$classes .= " nochildren";
630+
}
631+
632+
if (!$owner->canEdit() && !$owner->canAddChildren()) {
633+
if (!$owner->canView()) {
634+
$classes .= " disabled";
635+
} else {
636+
$classes .= " edit-disabled";
637+
}
638+
}
639+
640+
$owner->invokeWithExtensions('updateCMSTreeClasses', $classes);
641+
return $classes;
642+
}
643+
620644
/**
621645
* Find the first class in the inheritance chain that has Hierarchy extension applied
622646
*
@@ -777,6 +801,17 @@ public function getBreadcrumbs($separator = ' » ')
777801
return implode($separator ?? '', $crumbs);
778802
}
779803

804+
/**
805+
* Get the title that will be used in TreeDropdownField and other tree structures.
806+
*/
807+
public function getTreeTitle(): string
808+
{
809+
$owner = $this->getOwner();
810+
$title = $owner->MenuTitle ?: $owner->Title;
811+
$owner->extend('updateTreeTitle', $title);
812+
return $title ?? ''; // @TODO see if we need to escape this (it was escaped in Group and is in File too)
813+
}
814+
780815
/**
781816
* Get the name of the dedicated sort field, if there is one.
782817
*/

src/Security/Group.php

-10
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,6 @@ public function stageChildren()
494494
->sort('"Sort"');
495495
}
496496

497-
/**
498-
* @return string
499-
*/
500-
public function getTreeTitle()
501-
{
502-
$title = htmlspecialchars($this->Title ?? '', ENT_QUOTES);
503-
$this->extend('updateTreeTitle', $title);
504-
return $title;
505-
}
506-
507497
/**
508498
* Overloaded to ensure the code is always descent.
509499
*

src/Security/PermissionCheckable.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace SilverStripe\Security;
4+
5+
/**
6+
* Model with permissions that can be checked using PermissionChecker
7+
*/
8+
interface PermissionCheckable
9+
{
10+
/**
11+
* Get the permission checker for this model
12+
*/
13+
public function getPermissionChecker(): PermissionChecker;
14+
}

0 commit comments

Comments
 (0)