Completed
Push — master ( 1cf294...c4bc10 )
by
unknown
12s
created
src/Forms/GridFieldSiteTreeState.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,82 +15,82 @@
 block discarded – undo
15 15
 **/
16 16
 class GridFieldSiteTreeState implements GridField_ColumnProvider
17 17
 {
18
-    use Injectable;
18
+	use Injectable;
19 19
 
20
-    public function augmentColumns($gridField, &$columns)
21
-    {
22
-        // Ensure Actions always appears as the last column.
23
-        $key = array_search('Actions', $columns);
24
-        if ($key !== false) {
25
-            unset($columns[$key]);
26
-        }
20
+	public function augmentColumns($gridField, &$columns)
21
+	{
22
+		// Ensure Actions always appears as the last column.
23
+		$key = array_search('Actions', $columns);
24
+		if ($key !== false) {
25
+			unset($columns[$key]);
26
+		}
27 27
 
28
-        $columns = array_merge($columns, array(
29
-            'State',
30
-            'Actions',
31
-        ));
32
-    }
28
+		$columns = array_merge($columns, array(
29
+			'State',
30
+			'Actions',
31
+		));
32
+	}
33 33
 
34
-    public function getColumnsHandled($gridField)
35
-    {
36
-        return array('State');
37
-    }
34
+	public function getColumnsHandled($gridField)
35
+	{
36
+		return array('State');
37
+	}
38 38
 
39
-    public function getColumnContent($gridField, $record, $columnName)
40
-    {
41
-        if ($columnName == 'State') {
42
-            if ($record->hasMethod('isPublished')) {
43
-                $modifiedLabel = '';
44
-                if ($record->isModifiedOnStage) {
45
-                    $modifiedLabel = "<span class='modified'>" . _t(__CLASS__ . '.Modified', 'Modified') . '</span>';
46
-                }
39
+	public function getColumnContent($gridField, $record, $columnName)
40
+	{
41
+		if ($columnName == 'State') {
42
+			if ($record->hasMethod('isPublished')) {
43
+				$modifiedLabel = '';
44
+				if ($record->isModifiedOnStage) {
45
+					$modifiedLabel = "<span class='modified'>" . _t(__CLASS__ . '.Modified', 'Modified') . '</span>';
46
+				}
47 47
 
48
-                $published = $record->isPublished();
49
-                if (!$published) {
50
-                    return _t(
51
-                        __CLASS__ . '.Draft',
52
-                        '<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
53
-                        'State for when a post is saved.',
54
-                        array(
55
-                            'date' => $record->dbObject('LastEdited')->Nice()
56
-                        )
57
-                    );
58
-                }
59
-                return _t(
60
-                    __CLASS__ . '.Published',
61
-                    '<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
62
-                    'State for when a post is published.',
63
-                    array(
64
-                        'date' => $record->dbObject('LastEdited')->Nice()
65
-                    )
66
-                ) . $modifiedLabel;
67
-            }
68
-        }
69
-    }
48
+				$published = $record->isPublished();
49
+				if (!$published) {
50
+					return _t(
51
+						__CLASS__ . '.Draft',
52
+						'<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
53
+						'State for when a post is saved.',
54
+						array(
55
+							'date' => $record->dbObject('LastEdited')->Nice()
56
+						)
57
+					);
58
+				}
59
+				return _t(
60
+					__CLASS__ . '.Published',
61
+					'<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
62
+					'State for when a post is published.',
63
+					array(
64
+						'date' => $record->dbObject('LastEdited')->Nice()
65
+					)
66
+				) . $modifiedLabel;
67
+			}
68
+		}
69
+	}
70 70
 
71
-    public function getColumnAttributes($gridField, $record, $columnName)
72
-    {
73
-        if ($columnName == 'State') {
74
-            if ($record->hasMethod('isPublished')) {
75
-                $published = $record->isPublished();
76
-                if (!$published) {
77
-                    $class = 'gridfield-icon draft';
78
-                } else {
79
-                    $class = 'gridfield-icon published';
80
-                }
81
-                return array('class' => $class);
82
-            }
83
-        }
84
-        return array();
85
-    }
71
+	public function getColumnAttributes($gridField, $record, $columnName)
72
+	{
73
+		if ($columnName == 'State') {
74
+			if ($record->hasMethod('isPublished')) {
75
+				$published = $record->isPublished();
76
+				if (!$published) {
77
+					$class = 'gridfield-icon draft';
78
+				} else {
79
+					$class = 'gridfield-icon published';
80
+				}
81
+				return array('class' => $class);
82
+			}
83
+		}
84
+		return array();
85
+	}
86 86
 
87
-    public function getColumnMetaData($gridField, $columnName)
88
-    {
89
-        switch ($columnName) {
90
-            case 'State':
91
-                return array('title' => _t(__CLASS__ . '.StateTitle', 'State', 'Column title for state'));
92
-            default:
93
-                break;
94
-        }
95
-    }
87
+	public function getColumnMetaData($gridField, $columnName)
88
+	{
89
+		switch ($columnName) {
90
+			case 'State':
91
+				return array('title' => _t(__CLASS__ . '.StateTitle', 'State', 'Column title for state'));
92
+			default:
93
+				break;
94
+		}
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
             if ($record->hasMethod('isPublished')) {
43 43
                 $modifiedLabel = '';
44 44
                 if ($record->isModifiedOnStage) {
45
-                    $modifiedLabel = "<span class='modified'>" . _t(__CLASS__ . '.Modified', 'Modified') . '</span>';
45
+                    $modifiedLabel = "<span class='modified'>"._t(__CLASS__.'.Modified', 'Modified').'</span>';
46 46
                 }
47 47
 
48 48
                 $published = $record->isPublished();
49 49
                 if (!$published) {
50 50
                     return _t(
51
-                        __CLASS__ . '.Draft',
51
+                        __CLASS__.'.Draft',
52 52
                         '<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
53 53
                         'State for when a post is saved.',
54 54
                         array(
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
                     );
58 58
                 }
59 59
                 return _t(
60
-                    __CLASS__ . '.Published',
60
+                    __CLASS__.'.Published',
61 61
                     '<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
62 62
                     'State for when a post is published.',
63 63
                     array(
64 64
                         'date' => $record->dbObject('LastEdited')->Nice()
65 65
                     )
66
-                ) . $modifiedLabel;
66
+                ).$modifiedLabel;
67 67
             }
68 68
         }
69 69
     }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     {
89 89
         switch ($columnName) {
90 90
             case 'State':
91
-                return array('title' => _t(__CLASS__ . '.StateTitle', 'State', 'Column title for state'));
91
+                return array('title' => _t(__CLASS__.'.StateTitle', 'State', 'Column title for state'));
92 92
             default:
93 93
                 break;
94 94
         }
Please login to merge, or discard this patch.
src/Forms/GridFieldSiteTreeAddNewButton.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -30,141 +30,141 @@
 block discarded – undo
30 30
  */
31 31
 class GridFieldSiteTreeAddNewButton extends GridFieldAddNewButton implements GridField_ActionProvider
32 32
 {
33
-    /**
34
-     * Determine the list of classnames and titles allowed for a given parent object
35
-     *
36
-     * @param SiteTree $parent
37
-     * @return boolean
38
-     */
39
-    public function getAllowedChildren(SiteTree $parent = null)
40
-    {
41
-        if (!$parent || !$parent->canAddChildren()) {
42
-            return array();
43
-        }
44
-
45
-        $nonHiddenPageTypes = SiteTree::page_type_classes();
46
-        $allowedChildren = $parent->allowedChildren();
47
-        $children = array();
48
-        foreach ($allowedChildren as $class) {
49
-            if (Config::inst()->get($class, 'show_in_sitetree') === false) {
50
-                $instance = Injector::inst()->get($class);
51
-                // Note: Second argument to SiteTree::canCreate will support inherited permissions
52
-                // post 3.1.12, and will default to the old permission model in 3.1.11 or below
53
-                // See http://docs.silverstripe.org/en/changelogs/3.1.11
54
-                if ($instance->canCreate(null, array('Parent' => $parent)) && in_array($class, $nonHiddenPageTypes)) {
55
-                    $children[$class] = $instance->i18n_singular_name();
56
-                }
57
-            }
58
-        }
59
-        return $children;
60
-    }
61
-
62
-    public function getHTMLFragments($gridField)
63
-    {
64
-        $state = $gridField->State->GridFieldSiteTreeAddNewButton;
65
-
66
-        $parent = SiteTree::get()->byId(Controller::curr()->currentPageID());
67
-
68
-        if ($parent) {
69
-            $state->currentPageID = $parent->ID;
70
-        }
71
-
72
-        $children = $this->getAllowedChildren($parent);
73
-        if (empty($children)) {
74
-            return array();
75
-        } elseif (count($children) > 1) {
76
-            $pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild());
77
-            $pageTypes
78
-                ->setFieldHolderTemplate('GridFieldSiteTreeAddNewButton_holder')
79
-                ->addExtraClass('gridfield-dropdown no-change-track');
80
-
81
-            $state->pageType = $parent->defaultChild();
82
-
83
-            if (!$this->buttonName) {
84
-                $this->buttonName = _t(
85
-                    __CLASS__ . '.AddMultipleOptions',
86
-                    'Add new',
87
-                    'Add button text for multiple options.'
88
-                );
89
-            }
90
-        } else {
91
-            $keys = array_keys($children);
92
-            $pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]);
93
-
94
-            $state->pageType = $keys[0];
95
-
96
-            if (!$this->buttonName) {
97
-                $this->buttonName = _t(
98
-                    __CLASS__ . '.Add',
99
-                    'Add new {name}',
100
-                    'Add button text for a single option.',
101
-                    ['name' => $children[$keys[0]]]
102
-                );
103
-            }
104
-        }
105
-
106
-        $addAction = GridField_FormAction::create($gridField, 'add', $this->buttonName, 'add', 'add');
107
-        $addAction
108
-            ->setAttribute('data-icon', 'add')
109
-            ->addExtraClass('no-ajax btn btn-primary font-icon-plus');
110
-
111
-        $forTemplate = ArrayData::create();
112
-        $forTemplate->Fields = ArrayList::create();
113
-        $forTemplate->Fields->push($pageTypes);
114
-        $forTemplate->Fields->push($addAction);
115
-
116
-        Requirements::css('silverstripe/lumberjack:css/lumberjack.css');
117
-        Requirements::javascript('silverstripe/lumberjack:javascript/GridField.js');
118
-
119
-        return [$this->targetFragment => $forTemplate->renderWith(__CLASS__)];
120
-    }
121
-
122
-    /**
123
-     * Provide actions to this component.
124
-     *
125
-     * @param  GridField $gridField
126
-     * @return array
127
-    **/
128
-    public function getActions($gridField)
129
-    {
130
-        return array('add');
131
-    }
132
-
133
-    /**
134
-     * Handles the add action, but only acts as a wrapper for {@link CMSPageAddController::doAdd()}
135
-     *
136
-     * @param GridField $gridField
137
-     * @param string $actionName
138
-     * @param mixed $arguments
139
-     * @param array $data
140
-     *
141
-     * @return HTTPResponse|null
142
-     */
143
-    public function handleAction(GridField $gridField, $actionName, $arguments, $data)
144
-    {
145
-        if ($actionName == 'add') {
146
-            $tmpData = json_decode($data['ChildPages']['GridState'], true);
147
-            /** @skipUpgrade  */
148
-            $tmpData = $tmpData['GridFieldSiteTreeAddNewButton'];
149
-
150
-            $data = array(
151
-                'ParentID' => $tmpData['currentPageID'],
152
-                'PageType' => $tmpData['pageType']
153
-            );
154
-
155
-            /** @var $controller CMSPageAddController */
156
-            $controller = Injector::inst()->create(CMSPageAddController::class);
157
-
158
-            // pass current request to newly created controller
159
-            $request = Controller::curr()->getRequest();
160
-            $controller->setRequest($request);
161
-
162
-            $form = $controller->AddForm();
163
-            $form->loadDataFrom($data);
164
-
165
-            return $controller->doAdd($data, $form);
166
-        }
167
-
168
-        return null;
169
-    }
33
+	/**
34
+	 * Determine the list of classnames and titles allowed for a given parent object
35
+	 *
36
+	 * @param SiteTree $parent
37
+	 * @return boolean
38
+	 */
39
+	public function getAllowedChildren(SiteTree $parent = null)
40
+	{
41
+		if (!$parent || !$parent->canAddChildren()) {
42
+			return array();
43
+		}
44
+
45
+		$nonHiddenPageTypes = SiteTree::page_type_classes();
46
+		$allowedChildren = $parent->allowedChildren();
47
+		$children = array();
48
+		foreach ($allowedChildren as $class) {
49
+			if (Config::inst()->get($class, 'show_in_sitetree') === false) {
50
+				$instance = Injector::inst()->get($class);
51
+				// Note: Second argument to SiteTree::canCreate will support inherited permissions
52
+				// post 3.1.12, and will default to the old permission model in 3.1.11 or below
53
+				// See http://docs.silverstripe.org/en/changelogs/3.1.11
54
+				if ($instance->canCreate(null, array('Parent' => $parent)) && in_array($class, $nonHiddenPageTypes)) {
55
+					$children[$class] = $instance->i18n_singular_name();
56
+				}
57
+			}
58
+		}
59
+		return $children;
60
+	}
61
+
62
+	public function getHTMLFragments($gridField)
63
+	{
64
+		$state = $gridField->State->GridFieldSiteTreeAddNewButton;
65
+
66
+		$parent = SiteTree::get()->byId(Controller::curr()->currentPageID());
67
+
68
+		if ($parent) {
69
+			$state->currentPageID = $parent->ID;
70
+		}
71
+
72
+		$children = $this->getAllowedChildren($parent);
73
+		if (empty($children)) {
74
+			return array();
75
+		} elseif (count($children) > 1) {
76
+			$pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild());
77
+			$pageTypes
78
+				->setFieldHolderTemplate('GridFieldSiteTreeAddNewButton_holder')
79
+				->addExtraClass('gridfield-dropdown no-change-track');
80
+
81
+			$state->pageType = $parent->defaultChild();
82
+
83
+			if (!$this->buttonName) {
84
+				$this->buttonName = _t(
85
+					__CLASS__ . '.AddMultipleOptions',
86
+					'Add new',
87
+					'Add button text for multiple options.'
88
+				);
89
+			}
90
+		} else {
91
+			$keys = array_keys($children);
92
+			$pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]);
93
+
94
+			$state->pageType = $keys[0];
95
+
96
+			if (!$this->buttonName) {
97
+				$this->buttonName = _t(
98
+					__CLASS__ . '.Add',
99
+					'Add new {name}',
100
+					'Add button text for a single option.',
101
+					['name' => $children[$keys[0]]]
102
+				);
103
+			}
104
+		}
105
+
106
+		$addAction = GridField_FormAction::create($gridField, 'add', $this->buttonName, 'add', 'add');
107
+		$addAction
108
+			->setAttribute('data-icon', 'add')
109
+			->addExtraClass('no-ajax btn btn-primary font-icon-plus');
110
+
111
+		$forTemplate = ArrayData::create();
112
+		$forTemplate->Fields = ArrayList::create();
113
+		$forTemplate->Fields->push($pageTypes);
114
+		$forTemplate->Fields->push($addAction);
115
+
116
+		Requirements::css('silverstripe/lumberjack:css/lumberjack.css');
117
+		Requirements::javascript('silverstripe/lumberjack:javascript/GridField.js');
118
+
119
+		return [$this->targetFragment => $forTemplate->renderWith(__CLASS__)];
120
+	}
121
+
122
+	/**
123
+	 * Provide actions to this component.
124
+	 *
125
+	 * @param  GridField $gridField
126
+	 * @return array
127
+	 **/
128
+	public function getActions($gridField)
129
+	{
130
+		return array('add');
131
+	}
132
+
133
+	/**
134
+	 * Handles the add action, but only acts as a wrapper for {@link CMSPageAddController::doAdd()}
135
+	 *
136
+	 * @param GridField $gridField
137
+	 * @param string $actionName
138
+	 * @param mixed $arguments
139
+	 * @param array $data
140
+	 *
141
+	 * @return HTTPResponse|null
142
+	 */
143
+	public function handleAction(GridField $gridField, $actionName, $arguments, $data)
144
+	{
145
+		if ($actionName == 'add') {
146
+			$tmpData = json_decode($data['ChildPages']['GridState'], true);
147
+			/** @skipUpgrade  */
148
+			$tmpData = $tmpData['GridFieldSiteTreeAddNewButton'];
149
+
150
+			$data = array(
151
+				'ParentID' => $tmpData['currentPageID'],
152
+				'PageType' => $tmpData['pageType']
153
+			);
154
+
155
+			/** @var $controller CMSPageAddController */
156
+			$controller = Injector::inst()->create(CMSPageAddController::class);
157
+
158
+			// pass current request to newly created controller
159
+			$request = Controller::curr()->getRequest();
160
+			$controller->setRequest($request);
161
+
162
+			$form = $controller->AddForm();
163
+			$form->loadDataFrom($data);
164
+
165
+			return $controller->doAdd($data, $form);
166
+		}
167
+
168
+		return null;
169
+	}
170 170
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
             if (!$this->buttonName) {
84 84
                 $this->buttonName = _t(
85
-                    __CLASS__ . '.AddMultipleOptions',
85
+                    __CLASS__.'.AddMultipleOptions',
86 86
                     'Add new',
87 87
                     'Add button text for multiple options.'
88 88
                 );
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 
96 96
             if (!$this->buttonName) {
97 97
                 $this->buttonName = _t(
98
-                    __CLASS__ . '.Add',
98
+                    __CLASS__.'.Add',
99 99
                     'Add new {name}',
100 100
                     'Add button text for a single option.',
101 101
                     ['name' => $children[$keys[0]]]
Please login to merge, or discard this patch.
src/Model/Lumberjack.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -28,210 +28,210 @@
 block discarded – undo
28 28
  */
29 29
 class Lumberjack extends SiteTreeExtension
30 30
 {
31
-    /**
32
-     * Loops through subclasses of the owner (intended to be SiteTree) and checks if they've been hidden.
33
-     *
34
-     * @return array
35
-     **/
36
-    public function getExcludedSiteTreeClassNames()
37
-    {
38
-        $classes = array();
39
-        $siteTreeClasses = $this->owner->allowedChildren();
40
-
41
-        foreach ($siteTreeClasses as $class) {
42
-            if (Config::inst()->get($class, 'show_in_sitetree') === false) {
43
-                $classes[$class] = $class;
44
-            }
45
-        }
46
-
47
-        return $classes;
48
-    }
49
-
50
-    /**
51
-     * This is responsible for adding the child pages tab and gridfield.
52
-     *
53
-     * @param FieldList $fields
54
-     */
55
-    public function updateCMSFields(FieldList $fields)
56
-    {
57
-        $excluded = $this->owner->getExcludedSiteTreeClassNames();
58
-        if (!empty($excluded)) {
59
-            $pages = $this->getLumberjackPagesForGridfield($excluded);
60
-            $gridField = GridField::create(
61
-                'ChildPages',
62
-                $this->getLumberjackTitle(),
63
-                $pages,
64
-                $this->getLumberjackGridFieldConfig()
65
-            );
66
-
67
-            $tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField);
68
-            $fields->insertAfter($tab, 'Main');
69
-        }
70
-    }
71
-
72
-    /**
73
-     * Return children in the stage site.
74
-     *
75
-     * @param bool $showAll Include all of the elements, even those not shown in the menus. Only applicable when
76
-     *                      extension is applied to {@link SiteTree}.
77
-     * @return DataList
78
-     */
79
-    public function stageChildren($showAll = false)
80
-    {
81
-        $config = $this->owner->config();
82
-        $hideFromHierarchy = $config->get('hide_from_hierarchy');
83
-        $hideFromCMSTree = $config->get('hide_from_cms_tree');
84
-        $baseClass = $this->owner->baseClass();
85
-
86
-        $staged = $baseClass::get()
87
-            ->filter('ParentID', (int)$this->owner->ID)
88
-            ->exclude('ID', (int)$this->owner->ID);
89
-
90
-        if ($hideFromHierarchy) {
91
-            $staged = $staged->exclude('ClassName', $hideFromHierarchy);
92
-        }
93
-
94
-        if ($hideFromCMSTree && $this->showingCMSTree()) {
95
-            $staged = $staged->exclude('ClassName', $hideFromCMSTree);
96
-        }
97
-
98
-        if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
99
-            $staged = $staged->filter('ShowInMenus', 1);
100
-        }
101
-
102
-        $this->owner->extend("augmentStageChildren", $staged, $showAll);
103
-        $staged = $this->excludeSiteTreeClassNames($staged);
104
-        return $staged;
105
-    }
106
-
107
-    /**
108
-     * Excludes any hidden owner subclasses. Note that the returned DataList will be a different
109
-     * instance from the original.
110
-     *
111
-     * @param DataList $list
112
-     * @return DataList
113
-     */
114
-    protected function excludeSiteTreeClassNames($list)
115
-    {
116
-        $classNames = $this->owner->getExcludedSiteTreeClassNames();
117
-        if ($this->shouldFilter() && count($classNames)) {
118
-            // Filter the SiteTree
119
-            $list = $list->exclude('ClassName', $classNames);
120
-        }
121
-        return $list;
122
-    }
123
-
124
-    /**
125
-     * Return children in the live site, if it exists.
126
-     *
127
-     * @param bool $showAll              Include all of the elements, even those not shown in the menus. Only
128
-     *                                   applicable when extension is applied to {@link SiteTree}.
129
-     * @param bool $onlyDeletedFromStage Only return items that have been deleted from stage
130
-     * @return DataList
131
-     * @throws Exception
132
-     */
133
-    public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
134
-    {
135
-        if (!$this->owner->hasExtension(Versioned::class)) {
136
-            throw new Exception('Hierarchy->liveChildren() only works with Versioned extension applied');
137
-        }
138
-
139
-        $config = $this->owner->config();
140
-        $hideFromHierarchy = $config->get('hide_from_hierarchy');
141
-        $hideFromCMSTree = $config->get('hide_from_cms_tree');
142
-        $baseClass = $this->owner->baseClass();
143
-
144
-        $children = $baseClass::get()
145
-            ->filter('ParentID', (int)$this->owner->ID)
146
-            ->exclude('ID', (int)$this->owner->ID)
147
-            ->setDataQueryParam(array(
148
-                'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage',
149
-                'Versioned.stage' => 'Live'
150
-            ));
151
-
152
-        if ($hideFromHierarchy) {
153
-            $children = $children->exclude('ClassName', $hideFromHierarchy);
154
-        }
155
-
156
-        if ($hideFromCMSTree && $this->showingCMSTree()) {
157
-            $children = $children->exclude('ClassName', $hideFromCMSTree);
158
-        }
159
-
160
-        if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
161
-            $children = $children->filter('ShowInMenus', 1);
162
-        }
163
-        $children = $this->excludeSiteTreeClassNames($children);
164
-
165
-        return $children;
166
-    }
167
-
168
-    /**
169
-     * This returns the title for the tab and GridField. This can be overwritten
170
-     * in the owner class.
171
-     *
172
-     * @return string
173
-     */
174
-    protected function getLumberjackTitle()
175
-    {
176
-        if (method_exists($this->owner, 'getLumberjackTitle')) {
177
-            return $this->owner->getLumberjackTitle();
178
-        }
179
-
180
-        return _t(__CLASS__ . '.TabTitle', 'Child Pages');
181
-    }
182
-
183
-    /**
184
-     * This returns the gird field config for the lumberjack gridfield.
185
-     *
186
-     * @return GridFieldConfig_Lumberjack
187
-     */
188
-    protected function getLumberjackGridFieldConfig()
189
-    {
190
-        if (method_exists($this->owner, 'getLumberjackGridFieldConfig')) {
191
-            return $this->owner->getLumberjackGridFieldConfig();
192
-        }
193
-
194
-        return GridFieldConfig_Lumberjack::create();
195
-    }
196
-
197
-    /**
198
-     * Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
199
-     * NB: This only checks the current controller. See https://github.com/silverstripe/silverstripe-lumberjack/pull/60
200
-     * for a discussion around this.
201
-     *
202
-     * @return bool
203
-     */
204
-    protected function shouldFilter()
205
-    {
206
-        $controller = Controller::curr();
207
-
208
-        // relevant only for CMS
209
-        if (!($controller instanceof LeftAndMain)) {
210
-            return false;
211
-        }
212
-
213
-        return in_array($controller->getAction(), [
214
-            'index', 'show', 'treeview', 'listview', 'getsubtree'
215
-        ]);
216
-    }
217
-
218
-    /**
219
-     * Returns list of pages for the CMS gridfield
220
-     *
221
-     * This also allows the owner class to override this method, e.g. to provide custom ordering.
222
-     *
223
-     * @var array $excluded     List of class names excluded from the SiteTree
224
-     * @return DataList
225
-     */
226
-    public function getLumberjackPagesForGridfield($excluded = array())
227
-    {
228
-        if (method_exists($this->owner, 'getLumberjackPagesForGridfield')) {
229
-            return $this->owner->getLumberjackPagesForGridfield($excluded);
230
-        }
231
-
232
-        return SiteTree::get()->filter([
233
-            'ParentID' => $this->owner->ID,
234
-            'ClassName' => $excluded,
235
-        ]);
236
-    }
31
+	/**
32
+	 * Loops through subclasses of the owner (intended to be SiteTree) and checks if they've been hidden.
33
+	 *
34
+	 * @return array
35
+	 **/
36
+	public function getExcludedSiteTreeClassNames()
37
+	{
38
+		$classes = array();
39
+		$siteTreeClasses = $this->owner->allowedChildren();
40
+
41
+		foreach ($siteTreeClasses as $class) {
42
+			if (Config::inst()->get($class, 'show_in_sitetree') === false) {
43
+				$classes[$class] = $class;
44
+			}
45
+		}
46
+
47
+		return $classes;
48
+	}
49
+
50
+	/**
51
+	 * This is responsible for adding the child pages tab and gridfield.
52
+	 *
53
+	 * @param FieldList $fields
54
+	 */
55
+	public function updateCMSFields(FieldList $fields)
56
+	{
57
+		$excluded = $this->owner->getExcludedSiteTreeClassNames();
58
+		if (!empty($excluded)) {
59
+			$pages = $this->getLumberjackPagesForGridfield($excluded);
60
+			$gridField = GridField::create(
61
+				'ChildPages',
62
+				$this->getLumberjackTitle(),
63
+				$pages,
64
+				$this->getLumberjackGridFieldConfig()
65
+			);
66
+
67
+			$tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField);
68
+			$fields->insertAfter($tab, 'Main');
69
+		}
70
+	}
71
+
72
+	/**
73
+	 * Return children in the stage site.
74
+	 *
75
+	 * @param bool $showAll Include all of the elements, even those not shown in the menus. Only applicable when
76
+	 *                      extension is applied to {@link SiteTree}.
77
+	 * @return DataList
78
+	 */
79
+	public function stageChildren($showAll = false)
80
+	{
81
+		$config = $this->owner->config();
82
+		$hideFromHierarchy = $config->get('hide_from_hierarchy');
83
+		$hideFromCMSTree = $config->get('hide_from_cms_tree');
84
+		$baseClass = $this->owner->baseClass();
85
+
86
+		$staged = $baseClass::get()
87
+			->filter('ParentID', (int)$this->owner->ID)
88
+			->exclude('ID', (int)$this->owner->ID);
89
+
90
+		if ($hideFromHierarchy) {
91
+			$staged = $staged->exclude('ClassName', $hideFromHierarchy);
92
+		}
93
+
94
+		if ($hideFromCMSTree && $this->showingCMSTree()) {
95
+			$staged = $staged->exclude('ClassName', $hideFromCMSTree);
96
+		}
97
+
98
+		if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
99
+			$staged = $staged->filter('ShowInMenus', 1);
100
+		}
101
+
102
+		$this->owner->extend("augmentStageChildren", $staged, $showAll);
103
+		$staged = $this->excludeSiteTreeClassNames($staged);
104
+		return $staged;
105
+	}
106
+
107
+	/**
108
+	 * Excludes any hidden owner subclasses. Note that the returned DataList will be a different
109
+	 * instance from the original.
110
+	 *
111
+	 * @param DataList $list
112
+	 * @return DataList
113
+	 */
114
+	protected function excludeSiteTreeClassNames($list)
115
+	{
116
+		$classNames = $this->owner->getExcludedSiteTreeClassNames();
117
+		if ($this->shouldFilter() && count($classNames)) {
118
+			// Filter the SiteTree
119
+			$list = $list->exclude('ClassName', $classNames);
120
+		}
121
+		return $list;
122
+	}
123
+
124
+	/**
125
+	 * Return children in the live site, if it exists.
126
+	 *
127
+	 * @param bool $showAll              Include all of the elements, even those not shown in the menus. Only
128
+	 *                                   applicable when extension is applied to {@link SiteTree}.
129
+	 * @param bool $onlyDeletedFromStage Only return items that have been deleted from stage
130
+	 * @return DataList
131
+	 * @throws Exception
132
+	 */
133
+	public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
134
+	{
135
+		if (!$this->owner->hasExtension(Versioned::class)) {
136
+			throw new Exception('Hierarchy->liveChildren() only works with Versioned extension applied');
137
+		}
138
+
139
+		$config = $this->owner->config();
140
+		$hideFromHierarchy = $config->get('hide_from_hierarchy');
141
+		$hideFromCMSTree = $config->get('hide_from_cms_tree');
142
+		$baseClass = $this->owner->baseClass();
143
+
144
+		$children = $baseClass::get()
145
+			->filter('ParentID', (int)$this->owner->ID)
146
+			->exclude('ID', (int)$this->owner->ID)
147
+			->setDataQueryParam(array(
148
+				'Versioned.mode' => $onlyDeletedFromStage ? 'stage_unique' : 'stage',
149
+				'Versioned.stage' => 'Live'
150
+			));
151
+
152
+		if ($hideFromHierarchy) {
153
+			$children = $children->exclude('ClassName', $hideFromHierarchy);
154
+		}
155
+
156
+		if ($hideFromCMSTree && $this->showingCMSTree()) {
157
+			$children = $children->exclude('ClassName', $hideFromCMSTree);
158
+		}
159
+
160
+		if (!$showAll && DataObject::getSchema()->fieldSpec($this->owner, 'ShowInMenus')) {
161
+			$children = $children->filter('ShowInMenus', 1);
162
+		}
163
+		$children = $this->excludeSiteTreeClassNames($children);
164
+
165
+		return $children;
166
+	}
167
+
168
+	/**
169
+	 * This returns the title for the tab and GridField. This can be overwritten
170
+	 * in the owner class.
171
+	 *
172
+	 * @return string
173
+	 */
174
+	protected function getLumberjackTitle()
175
+	{
176
+		if (method_exists($this->owner, 'getLumberjackTitle')) {
177
+			return $this->owner->getLumberjackTitle();
178
+		}
179
+
180
+		return _t(__CLASS__ . '.TabTitle', 'Child Pages');
181
+	}
182
+
183
+	/**
184
+	 * This returns the gird field config for the lumberjack gridfield.
185
+	 *
186
+	 * @return GridFieldConfig_Lumberjack
187
+	 */
188
+	protected function getLumberjackGridFieldConfig()
189
+	{
190
+		if (method_exists($this->owner, 'getLumberjackGridFieldConfig')) {
191
+			return $this->owner->getLumberjackGridFieldConfig();
192
+		}
193
+
194
+		return GridFieldConfig_Lumberjack::create();
195
+	}
196
+
197
+	/**
198
+	 * Checks if we're on a controller where we should filter. ie. Are we loading the SiteTree?
199
+	 * NB: This only checks the current controller. See https://github.com/silverstripe/silverstripe-lumberjack/pull/60
200
+	 * for a discussion around this.
201
+	 *
202
+	 * @return bool
203
+	 */
204
+	protected function shouldFilter()
205
+	{
206
+		$controller = Controller::curr();
207
+
208
+		// relevant only for CMS
209
+		if (!($controller instanceof LeftAndMain)) {
210
+			return false;
211
+		}
212
+
213
+		return in_array($controller->getAction(), [
214
+			'index', 'show', 'treeview', 'listview', 'getsubtree'
215
+		]);
216
+	}
217
+
218
+	/**
219
+	 * Returns list of pages for the CMS gridfield
220
+	 *
221
+	 * This also allows the owner class to override this method, e.g. to provide custom ordering.
222
+	 *
223
+	 * @var array $excluded     List of class names excluded from the SiteTree
224
+	 * @return DataList
225
+	 */
226
+	public function getLumberjackPagesForGridfield($excluded = array())
227
+	{
228
+		if (method_exists($this->owner, 'getLumberjackPagesForGridfield')) {
229
+			return $this->owner->getLumberjackPagesForGridfield($excluded);
230
+		}
231
+
232
+		return SiteTree::get()->filter([
233
+			'ParentID' => $this->owner->ID,
234
+			'ClassName' => $excluded,
235
+		]);
236
+	}
237 237
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@
 block discarded – undo
177 177
             return $this->owner->getLumberjackTitle();
178 178
         }
179 179
 
180
-        return _t(__CLASS__ . '.TabTitle', 'Child Pages');
180
+        return _t(__CLASS__.'.TabTitle', 'Child Pages');
181 181
     }
182 182
 
183 183
     /**
Please login to merge, or discard this patch.