Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Move logic from silverstripe/cms into central place #11439

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading