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
15
_config.php
15
_config.php
@ -1,31 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\Admin\CMSMenu;
|
use SilverStripe\Admin\CMSMenu;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||||
use SilverStripe\Assets\File;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - CMS_DIR: Path relative to webroot, e.g. "cms"
|
* - CMS_DIR: Path relative to webroot, e.g. "cms"
|
||||||
* - CMS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/cms"
|
* - CMS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/cms"
|
||||||
*/
|
*/
|
||||||
define('CMS_PATH', realpath(__DIR__));
|
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));
|
define('CMS_DIR', trim(substr(CMS_PATH, strlen(BASE_PATH)), DIRECTORY_SEPARATOR));
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Path error: CMS_PATH " . CMS_PATH . " not within BASE_PATH " . BASE_PATH);
|
throw new Exception("Path error: CMS_PATH " . CMS_PATH . " not within BASE_PATH " . BASE_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the default internal shortcodes.
|
* Register the default internal shortcodes.
|
||||||
*/
|
*/
|
||||||
ShortcodeParser::get('default')->register(
|
ShortcodeParser::get('default')->register(
|
||||||
'sitetree_link',
|
'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
|
// 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\\CMSMain');
|
||||||
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageEditController');
|
CMSMenu::remove_menu_class('SilverStripe\\CMS\\Controllers\\CMSPageEditController');
|
||||||
|
@ -10,3 +10,4 @@ SilverStripe\Forms\Form:
|
|||||||
SilverStripe\Assets\File:
|
SilverStripe\Assets\File:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\CMS\Controllers\ErrorPageFileExtension
|
- SilverStripe\CMS\Controllers\ErrorPageFileExtension
|
||||||
|
- SilverStripe\CMS\Model\SiteTreeFileExtension
|
||||||
|
@ -995,7 +995,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
return true;
|
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())
|
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();
|
$member = Member::currentUserID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2713,25 +2713,36 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
*/
|
*/
|
||||||
public function allowedChildren()
|
public function allowedChildren()
|
||||||
{
|
{
|
||||||
$allowedChildren = array();
|
// Get config based on old FIRST_SET rules
|
||||||
$candidates = $this->stat('allowed_children');
|
$candidates = null;
|
||||||
if ($candidates && $candidates != "none" && $candidates != "SiteTree_root") {
|
$class = get_class($this);
|
||||||
foreach ($candidates as $candidate) {
|
while ($class) {
|
||||||
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
|
if (Config::inst()->exists($class, 'allowed_children', Config::UNINHERITED)) {
|
||||||
// Otherwise, the class and all its subclasses are allowed.
|
$candidates = Config::inst()->get($class, 'allowed_children', Config::UNINHERITED);
|
||||||
if (substr($candidate, 0, 1) == '*') {
|
break;
|
||||||
$allowedChildren[] = substr($candidate, 1);
|
}
|
||||||
} elseif ($subclasses = ClassInfo::subclassesFor($candidate)) {
|
$class = get_parent_class($class);
|
||||||
foreach ($subclasses as $subclass) {
|
}
|
||||||
if ($subclass == 'SiteTree_root' || singleton($subclass) instanceof HiddenClass) {
|
if (!$candidates || $candidates === 'none' || $candidates === 'SiteTree_root') {
|
||||||
continue;
|
return [];
|
||||||
}
|
}
|
||||||
$allowedChildren[] = $subclass;
|
|
||||||
|
// 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.
|
||||||
|
if (substr($candidate, 0, 1) == '*') {
|
||||||
|
$allowedChildren[] = substr($candidate, 1);
|
||||||
|
} elseif ($subclasses = ClassInfo::subclassesFor($candidate)) {
|
||||||
|
foreach ($subclasses as $subclass) {
|
||||||
|
if ($subclass == 'SiteTree_root' || singleton($subclass) instanceof HiddenClass) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
$allowedChildren[] = $subclass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $allowedChildren;
|
return $allowedChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user