BUG Fix allowedChildren() and link tracking

This commit is contained in:
Damian Mooyman 2017-02-28 15:46:07 +13:00
parent 4885736b0e
commit dfe25c27f0
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
3 changed files with 35 additions and 26 deletions

View File

@ -1,9 +1,8 @@
<?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"
@ -21,11 +20,9 @@ if(strpos(CMS_PATH, BASE_PATH) === 0) {
*/ */
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');

View File

@ -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

View File

@ -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,9 +2713,22 @@ 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);
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) { foreach ($candidates as $candidate) {
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses. // 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. // Otherwise, the class and all its subclasses are allowed.
@ -2730,8 +2743,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
} }
} }
}
return $allowedChildren; return $allowedChildren;
} }