@@ -6,7 +6,6 @@ |
||
6 | 6 | use SilverStripe\CMS\Model\SiteTree; |
7 | 7 | use SilverStripe\CMS\Model\SiteTreeExtension; |
8 | 8 | use SilverStripe\Control\Controller; |
9 | -use SilverStripe\Core\ClassInfo; |
|
10 | 9 | use SilverStripe\Core\Config\Config; |
11 | 10 | use SilverStripe\Forms\FieldList; |
12 | 11 | use SilverStripe\Forms\GridField\GridField; |
@@ -25,158 +25,158 @@ |
||
25 | 25 | */ |
26 | 26 | class Lumberjack extends SiteTreeExtension |
27 | 27 | { |
28 | - /** |
|
29 | - * Loops through subclasses of the owner (intended to be SiteTree) and checks if they've been hidden. |
|
30 | - * |
|
31 | - * @return array |
|
32 | - **/ |
|
33 | - public function getExcludedSiteTreeClassNames() |
|
34 | - { |
|
35 | - $classes = array(); |
|
36 | - $siteTreeClasses = $this->owner->allowedChildren(); |
|
37 | - foreach ($siteTreeClasses as $class) { |
|
38 | - if (Config::inst()->get($class, 'show_in_sitetree') === false) { |
|
39 | - $classes[$class] = $class; |
|
40 | - } |
|
41 | - } |
|
42 | - return $classes; |
|
43 | - } |
|
28 | + /** |
|
29 | + * Loops through subclasses of the owner (intended to be SiteTree) and checks if they've been hidden. |
|
30 | + * |
|
31 | + * @return array |
|
32 | + **/ |
|
33 | + public function getExcludedSiteTreeClassNames() |
|
34 | + { |
|
35 | + $classes = array(); |
|
36 | + $siteTreeClasses = $this->owner->allowedChildren(); |
|
37 | + foreach ($siteTreeClasses as $class) { |
|
38 | + if (Config::inst()->get($class, 'show_in_sitetree') === false) { |
|
39 | + $classes[$class] = $class; |
|
40 | + } |
|
41 | + } |
|
42 | + return $classes; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * This is responsible for adding the child pages tab and gridfield. |
|
47 | - * |
|
48 | - * @param FieldList $fields |
|
49 | - */ |
|
50 | - public function updateCMSFields(FieldList $fields) |
|
51 | - { |
|
52 | - $excluded = $this->owner->getExcludedSiteTreeClassNames(); |
|
53 | - if (!empty($excluded)) { |
|
54 | - $pages = $this->getLumberjackPagesForGridfield($excluded); |
|
55 | - $gridField = GridField::create( |
|
56 | - 'ChildPages', |
|
57 | - $this->getLumberjackTitle(), |
|
58 | - $pages, |
|
59 | - $this->getLumberjackGridFieldConfig() |
|
60 | - ); |
|
45 | + /** |
|
46 | + * This is responsible for adding the child pages tab and gridfield. |
|
47 | + * |
|
48 | + * @param FieldList $fields |
|
49 | + */ |
|
50 | + public function updateCMSFields(FieldList $fields) |
|
51 | + { |
|
52 | + $excluded = $this->owner->getExcludedSiteTreeClassNames(); |
|
53 | + if (!empty($excluded)) { |
|
54 | + $pages = $this->getLumberjackPagesForGridfield($excluded); |
|
55 | + $gridField = GridField::create( |
|
56 | + 'ChildPages', |
|
57 | + $this->getLumberjackTitle(), |
|
58 | + $pages, |
|
59 | + $this->getLumberjackGridFieldConfig() |
|
60 | + ); |
|
61 | 61 | |
62 | - $tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField); |
|
63 | - $fields->insertAfter($tab, 'Main'); |
|
64 | - } |
|
65 | - } |
|
62 | + $tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField); |
|
63 | + $fields->insertAfter($tab, 'Main'); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Augments (@link Hierarchy::stageChildren()} |
|
69 | - * |
|
70 | - * @param boolean $showAll Include all of the elements, even those not shown in the menus. |
|
71 | - * (only applicable when extension is applied to {@link SiteTree}). |
|
72 | - * @return DataList |
|
73 | - */ |
|
74 | - public function stageChildren($showAll = false) |
|
75 | - { |
|
76 | - $baseClass = $this->owner->baseClass(); |
|
77 | - $staged = $baseClass::get() |
|
78 | - ->filter('ParentID', (int)$this->owner->ID) |
|
79 | - ->exclude('ID', (int)$this->owner->ID); |
|
80 | - if (!$showAll && $this->owner->dbObject('ShowInMenus')) { |
|
81 | - $staged = $staged->filter('ShowInMenus', 1); |
|
82 | - } |
|
83 | - $this->owner->extend('augmentStageChildren', $staged, $showAll); |
|
67 | + /** |
|
68 | + * Augments (@link Hierarchy::stageChildren()} |
|
69 | + * |
|
70 | + * @param boolean $showAll Include all of the elements, even those not shown in the menus. |
|
71 | + * (only applicable when extension is applied to {@link SiteTree}). |
|
72 | + * @return DataList |
|
73 | + */ |
|
74 | + public function stageChildren($showAll = false) |
|
75 | + { |
|
76 | + $baseClass = $this->owner->baseClass(); |
|
77 | + $staged = $baseClass::get() |
|
78 | + ->filter('ParentID', (int)$this->owner->ID) |
|
79 | + ->exclude('ID', (int)$this->owner->ID); |
|
80 | + if (!$showAll && $this->owner->dbObject('ShowInMenus')) { |
|
81 | + $staged = $staged->filter('ShowInMenus', 1); |
|
82 | + } |
|
83 | + $this->owner->extend('augmentStageChildren', $staged, $showAll); |
|
84 | 84 | |
85 | - if ($this->shouldFilter()) { |
|
86 | - // Filter the SiteTree |
|
87 | - return $staged->exclude('ClassName', $this->owner->getExcludedSiteTreeClassNames()); |
|
88 | - } |
|
89 | - return $staged; |
|
90 | - } |
|
85 | + if ($this->shouldFilter()) { |
|
86 | + // Filter the SiteTree |
|
87 | + return $staged->exclude('ClassName', $this->owner->getExcludedSiteTreeClassNames()); |
|
88 | + } |
|
89 | + return $staged; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Augments (@link Hierarchy::liveChildren()} by hiding excluded child classnames |
|
94 | - * |
|
95 | - * @param boolean $showAll Include all of the elements, even those not shown in the menus. |
|
96 | - * (only applicable when extension is applied to {@link SiteTree}). |
|
97 | - * @param boolean $onlyDeletedFromStage Only return items that have been deleted from stage |
|
98 | - * @return SS_List |
|
99 | - */ |
|
100 | - public function liveChildren($showAll = false, $onlyDeletedFromStage = false) |
|
101 | - { |
|
102 | - $baseClass = $this->owner->baseClass(); |
|
103 | - $children = $baseClass::get() |
|
104 | - ->filter('ParentID', (int)$this->owner->ID) |
|
105 | - ->exclude('ID', (int)$this->owner->ID) |
|
106 | - ->setDataQueryParam(array( |
|
107 | - 'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage', |
|
108 | - 'Versioned.stage' => 'Live' |
|
109 | - )); |
|
92 | + /** |
|
93 | + * Augments (@link Hierarchy::liveChildren()} by hiding excluded child classnames |
|
94 | + * |
|
95 | + * @param boolean $showAll Include all of the elements, even those not shown in the menus. |
|
96 | + * (only applicable when extension is applied to {@link SiteTree}). |
|
97 | + * @param boolean $onlyDeletedFromStage Only return items that have been deleted from stage |
|
98 | + * @return SS_List |
|
99 | + */ |
|
100 | + public function liveChildren($showAll = false, $onlyDeletedFromStage = false) |
|
101 | + { |
|
102 | + $baseClass = $this->owner->baseClass(); |
|
103 | + $children = $baseClass::get() |
|
104 | + ->filter('ParentID', (int)$this->owner->ID) |
|
105 | + ->exclude('ID', (int)$this->owner->ID) |
|
106 | + ->setDataQueryParam(array( |
|
107 | + 'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage', |
|
108 | + 'Versioned.stage' => 'Live' |
|
109 | + )); |
|
110 | 110 | |
111 | - if (!$showAll) { |
|
112 | - $children = $children->filter('ShowInMenus', 1); |
|
113 | - } |
|
111 | + if (!$showAll) { |
|
112 | + $children = $children->filter('ShowInMenus', 1); |
|
113 | + } |
|
114 | 114 | |
115 | - if ($this->shouldFilter()) { |
|
116 | - // Filter the SiteTree |
|
117 | - return $children->exclude('ClassName', $this->owner->getExcludedSiteTreeClassNames()); |
|
118 | - } |
|
119 | - return $children; |
|
120 | - } |
|
115 | + if ($this->shouldFilter()) { |
|
116 | + // Filter the SiteTree |
|
117 | + return $children->exclude('ClassName', $this->owner->getExcludedSiteTreeClassNames()); |
|
118 | + } |
|
119 | + return $children; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * This returns the title for the tab and GridField. This can be overwritten |
|
124 | - * in the owner class. |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function getLumberjackTitle() |
|
129 | - { |
|
130 | - if (method_exists($this->owner, 'getLumberjackTitle')) { |
|
131 | - return $this->owner->getLumberjackTitle(); |
|
132 | - } |
|
133 | - return _t('Lumberjack.TabTitle', 'Child Pages'); |
|
134 | - } |
|
122 | + /** |
|
123 | + * This returns the title for the tab and GridField. This can be overwritten |
|
124 | + * in the owner class. |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function getLumberjackTitle() |
|
129 | + { |
|
130 | + if (method_exists($this->owner, 'getLumberjackTitle')) { |
|
131 | + return $this->owner->getLumberjackTitle(); |
|
132 | + } |
|
133 | + return _t('Lumberjack.TabTitle', 'Child Pages'); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * This returns the gird field config for the lumberjack gridfield. |
|
138 | - * |
|
139 | - * @return GridFieldConfig |
|
140 | - */ |
|
141 | - protected function getLumberjackGridFieldConfig() |
|
142 | - { |
|
143 | - if (method_exists($this->owner, 'getLumberjackGridFieldConfig')) { |
|
144 | - return $this->owner->getLumberjackGridFieldConfig(); |
|
145 | - } |
|
146 | - return GridFieldConfig_Lumberjack::create(); |
|
147 | - } |
|
136 | + /** |
|
137 | + * This returns the gird field config for the lumberjack gridfield. |
|
138 | + * |
|
139 | + * @return GridFieldConfig |
|
140 | + */ |
|
141 | + protected function getLumberjackGridFieldConfig() |
|
142 | + { |
|
143 | + if (method_exists($this->owner, 'getLumberjackGridFieldConfig')) { |
|
144 | + return $this->owner->getLumberjackGridFieldConfig(); |
|
145 | + } |
|
146 | + return GridFieldConfig_Lumberjack::create(); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree? |
|
151 | - * |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - protected function shouldFilter() |
|
155 | - { |
|
156 | - $controller = Controller::curr(); |
|
157 | - return $controller instanceof LeftAndMain |
|
158 | - && in_array($controller->getAction(), array('treeview', 'listview', 'getsubtree')); |
|
159 | - } |
|
149 | + /** |
|
150 | + * Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree? |
|
151 | + * |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + protected function shouldFilter() |
|
155 | + { |
|
156 | + $controller = Controller::curr(); |
|
157 | + return $controller instanceof LeftAndMain |
|
158 | + && in_array($controller->getAction(), array('treeview', 'listview', 'getsubtree')); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Returns list of pages for the CMS gridfield |
|
163 | - * |
|
164 | - * This also allows the owner class to override this method, e.g. to provide custom ordering. |
|
165 | - * |
|
166 | - * @var array $excluded List of class names excluded from the SiteTree |
|
167 | - * @return DataList |
|
168 | - */ |
|
169 | - public function getLumberjackPagesForGridfield($excluded = array()) |
|
170 | - { |
|
171 | - if (method_exists($this->owner, 'getLumberjackPagesForGridfield')) { |
|
172 | - return $this->owner->getLumberjackPagesForGridfield($excluded); |
|
173 | - } |
|
161 | + /** |
|
162 | + * Returns list of pages for the CMS gridfield |
|
163 | + * |
|
164 | + * This also allows the owner class to override this method, e.g. to provide custom ordering. |
|
165 | + * |
|
166 | + * @var array $excluded List of class names excluded from the SiteTree |
|
167 | + * @return DataList |
|
168 | + */ |
|
169 | + public function getLumberjackPagesForGridfield($excluded = array()) |
|
170 | + { |
|
171 | + if (method_exists($this->owner, 'getLumberjackPagesForGridfield')) { |
|
172 | + return $this->owner->getLumberjackPagesForGridfield($excluded); |
|
173 | + } |
|
174 | 174 | |
175 | - return SiteTree::get()->filter( |
|
176 | - array( |
|
177 | - 'ParentID' => $this->owner->ID, |
|
178 | - 'ClassName' => $excluded, |
|
179 | - ) |
|
180 | - ); |
|
181 | - } |
|
175 | + return SiteTree::get()->filter( |
|
176 | + array( |
|
177 | + 'ParentID' => $this->owner->ID, |
|
178 | + 'ClassName' => $excluded, |
|
179 | + ) |
|
180 | + ); |
|
181 | + } |
|
182 | 182 | } |