mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUG Fix allowedChildren() and link tracking
This commit is contained in:
parent
4885736b0e
commit
dfe25c27f0
@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Admin\CMSMenu;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
use SilverStripe\Assets\File;
|
||||
|
||||
|
||||
/**
|
||||
* - CMS_DIR: Path relative to webroot, e.g. "cms"
|
||||
* - CMS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/cms"
|
||||
*/
|
||||
define('CMS_PATH', realpath(__DIR__));
|
||||
if(strpos(CMS_PATH, BASE_PATH) === 0) {
|
||||
if (strpos(CMS_PATH, BASE_PATH) === 0) {
|
||||
define('CMS_DIR', trim(substr(CMS_PATH, strlen(BASE_PATH)), DIRECTORY_SEPARATOR));
|
||||
} else {
|
||||
throw new Exception("Path error: CMS_PATH " . CMS_PATH . " not within BASE_PATH " . BASE_PATH);
|
||||
@ -21,11 +20,9 @@ if(strpos(CMS_PATH, BASE_PATH) === 0) {
|
||||
*/
|
||||
ShortcodeParser::get('default')->register(
|
||||
'sitetree_link',
|
||||
array('SilverStripe\\CMS\\Model\\SiteTree', 'link_shortcode_handler')
|
||||
array(SiteTree::class, 'link_shortcode_handler')
|
||||
);
|
||||
|
||||
File::add_extension('SilverStripe\\CMS\\Model\\SiteTreeFileExtension');
|
||||
|
||||
// TODO Remove once we can configure CMSMenu through static, nested configuration files
|
||||
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSMain');
|
||||
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageEditController');
|
||||
|
@ -10,3 +10,4 @@ SilverStripe\Forms\Form:
|
||||
SilverStripe\Assets\File:
|
||||
extensions:
|
||||
- SilverStripe\CMS\Controllers\ErrorPageFileExtension
|
||||
- SilverStripe\CMS\Model\SiteTreeFileExtension
|
||||
|
@ -995,7 +995,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->canEdit($member) && $this->stat('allowed_children') != 'none';
|
||||
return $this->canEdit($member) && $this->stat('allowed_children') !== 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1160,7 +1160,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
*/
|
||||
public function canCreate($member = null, $context = array())
|
||||
{
|
||||
if (!$member || !(is_a($member, 'SilverStripe\\Security\\Member')) || is_numeric($member)) {
|
||||
if (!$member || !(is_a($member, Member::class)) || is_numeric($member)) {
|
||||
$member = Member::currentUserID();
|
||||
}
|
||||
|
||||
@ -2713,9 +2713,22 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
*/
|
||||
public function allowedChildren()
|
||||
{
|
||||
$allowedChildren = array();
|
||||
$candidates = $this->stat('allowed_children');
|
||||
if ($candidates && $candidates != "none" && $candidates != "SiteTree_root") {
|
||||
// Get config based on old FIRST_SET rules
|
||||
$candidates = null;
|
||||
$class = get_class($this);
|
||||
while ($class) {
|
||||
if (Config::inst()->exists($class, 'allowed_children', Config::UNINHERITED)) {
|
||||
$candidates = Config::inst()->get($class, 'allowed_children', Config::UNINHERITED);
|
||||
break;
|
||||
}
|
||||
$class = get_parent_class($class);
|
||||
}
|
||||
if (!$candidates || $candidates === 'none' || $candidates === 'SiteTree_root') {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Parse candidate list
|
||||
$allowedChildren = [];
|
||||
foreach ($candidates as $candidate) {
|
||||
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
|
||||
// Otherwise, the class and all its subclasses are allowed.
|
||||
@ -2730,8 +2743,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allowedChildren;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user