Source of file Lumberjack.php
Size: 2,937 Bytes - Last Modified: 2021-12-23T10:04:28+00:00
/var/www/docs.ssmods.com/process/src/code/extensions/Lumberjack.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 | <?php /** * Class Lumberjack * * Add this classes to SiteTree classes which children should be hidden. * * @package silverstripe * @subpackage lumberjack * * @author Michael Strong <mstrong@silverstripe.org> */ class Lumberjack extends Hierarchy { /** * Loops through subclasses of the owner (intended to be SiteTree) and checks if they've been hidden. * * @return array **/ public function getExcludedSiteTreeClassNames() { $classes = array(); $siteTreeClasses = $this->owner->allowedChildren(); foreach($siteTreeClasses as $class) { if(Injector::inst()->create($class)->config()->show_in_sitetree === false) { $classes[$class] = $class; } } return $classes; } /** * This is responsible for adding the child pages tab and gridfield. * * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { $excluded = $this->owner->getExcludedSiteTreeClassNames(); if(!empty($excluded)) { $pages = SiteTree::get()->filter(array( 'ParentID' => $this->owner->ID, 'ClassName' => $excluded )); $gridField = new GridField( "ChildPages", $this->getLumberjackTitle(), $pages, GridFieldConfig_Lumberjack::create() ); $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField); $fields->insertAfter($tab, 'Main'); } } /** * Augments (@link Hierarchy::stageChildren()} * * @param $staged DataList * @param $showAll boolean **/ public function stageChildren($showAll = false) { $staged = parent::stageChildren($showAll); if($this->shouldFilter()) { // Filter the SiteTree return $staged->exclude("ClassName", $this->owner->getExcludedSiteTreeClassNames()); } return $staged; } /** * Augments (@link Hierarchy::liveChildren()} * * @param $staged DataList * @param $showAll boolean **/ public function liveChildren($showAll = false, $onlyDeletedFromStage = false) { $staged = parent::liveChildren($showAll, $onlyDeletedFromStage); if($this->shouldFilter()) { // Filter the SiteTree return $staged->exclude("ClassName", $this->owner->getExcludedSiteTreeClassNames()); } } /** * This returns the title for the tab and GridField. This can be overwritten * in the owner class. * * @return string */ protected function getLumberjackTitle() { if(method_exists($this->owner, 'getLumberjackTitle')) { return $this->owner->getLumberjackTitle(); } return _t("Lumberjack.TabTitle", "Child Pages"); } /** * Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree? * * @return bool */ protected function shouldFilter() { $controller = Controller::curr(); return $controller instanceof LeftAndMain && in_array($controller->getAction(), array("treeview", "listview", "getsubtree")); } } |