Last active
August 29, 2015 14:15
-
-
Save kinglozzer/789ae95c042e63a4d3a8 to your computer and use it in GitHub Desktop.
SilverStripe Page::$disallowed_children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMSMain: | |
extensions: | |
- DisallowedChildrenExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements "disallowed children" functionality for page classes. Usage: | |
* private static $disallowed_children = array( | |
* 'SomePageType', | |
* 'SomeOtherPageType' | |
* ); | |
* Note: not fully tested (e.g. does this prevent changing parent in "Settings" tab?) | |
* @author Loz Calver <kinglozzer@gmail.com> | |
*/ | |
class DisallowedChildrenExtension extends Extension { | |
/** | |
* @param array &$def | |
*/ | |
public function updateSiteTreeHints(array &$def) { | |
if(empty($def)) continue; | |
foreach($def as $class => $data) { | |
if(in_array($class, array('All', 'Root'))) continue; | |
$singleton = singleton($class); | |
$disallowed = $singleton->stat('disallowed_children'); | |
if(isset($disallowed) && ! empty($disallowed)) { | |
$orig = isset($data['disallowedChildren']) ? $data['disallowedChildren'] : array(); | |
$disallowed = array_unique(array_merge($orig, $disallowed)); | |
$def[$class]['disallowedChildren'] = array_values($disallowed); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment