@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | protected function filteredClassNames($classNames, $explicitClassNames) |
41 | 41 | { |
42 | - $classNames = array_filter($classNames, function ($value) use ($explicitClassNames) { |
|
42 | + $classNames = array_filter($classNames, function($value) use ($explicitClassNames) { |
|
43 | 43 | return in_array($value, $explicitClassNames); |
44 | 44 | }); |
45 | 45 | return $classNames; |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use SilverStripe\Core\Config\Config; |
6 | 6 | use SilverStripe\CMS\Model\SiteTree; |
7 | 7 | use SilverStripe\Dev\SapphireTest; |
8 | -use SilverStripe\Dev\TestOnly; |
|
9 | 8 | use SilverStripe\Lumberjack\Tests\Stub\SiteTree\LumberjackStub; |
10 | 9 | use SilverStripe\Lumberjack\Tests\Stub\SiteTree\LumberjackHiddenStub; |
11 | 10 | use SilverStripe\Lumberjack\Tests\Stub\SiteTree\LumberjackShownStub; |
@@ -12,54 +12,54 @@ |
||
12 | 12 | |
13 | 13 | class LumberjackTest extends SapphireTest |
14 | 14 | { |
15 | - /** |
|
16 | - * {@inheritDoc} |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected static $fixture_file = 'fixtures.yml'; |
|
15 | + /** |
|
16 | + * {@inheritDoc} |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected static $fixture_file = 'fixtures.yml'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected static $extra_dataobjects = [ |
|
25 | - LumberjackStub::class, |
|
26 | - LumberjackHiddenStub::class, |
|
27 | - LumberjackShownStub::class, |
|
28 | - ]; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected static $extra_dataobjects = [ |
|
25 | + LumberjackStub::class, |
|
26 | + LumberjackHiddenStub::class, |
|
27 | + LumberjackShownStub::class, |
|
28 | + ]; |
|
29 | 29 | |
30 | - public function testGetExcludedSiteTreeClassNames() |
|
31 | - { |
|
32 | - $standard = $this->objFromFixture(LumberjackStub::class, 'standard'); |
|
30 | + public function testGetExcludedSiteTreeClassNames() |
|
31 | + { |
|
32 | + $standard = $this->objFromFixture(LumberjackStub::class, 'standard'); |
|
33 | 33 | |
34 | - $excluded = $standard->getExcludedSiteTreeClassNames(); |
|
35 | - $excluded = $this->filteredClassNames($excluded, self::$extra_dataobjects); |
|
36 | - $this->assertEquals($excluded, array(LumberjackHiddenStub::class => LumberjackHiddenStub::class)); |
|
34 | + $excluded = $standard->getExcludedSiteTreeClassNames(); |
|
35 | + $excluded = $this->filteredClassNames($excluded, self::$extra_dataobjects); |
|
36 | + $this->assertEquals($excluded, array(LumberjackHiddenStub::class => LumberjackHiddenStub::class)); |
|
37 | 37 | |
38 | - Config::modify()->set(SiteTree::class, 'show_in_sitetree', false); |
|
39 | - $excluded = $standard->getExcludedSiteTreeClassNames(); |
|
40 | - $excluded = $this->filteredClassNames($excluded, self::$extra_dataobjects); |
|
41 | - $this->assertEquals( |
|
42 | - $excluded, |
|
43 | - array( |
|
44 | - LumberjackStub::class => LumberjackStub::class, |
|
45 | - LumberjackHiddenStub::class => LumberjackHiddenStub::class |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
38 | + Config::modify()->set(SiteTree::class, 'show_in_sitetree', false); |
|
39 | + $excluded = $standard->getExcludedSiteTreeClassNames(); |
|
40 | + $excluded = $this->filteredClassNames($excluded, self::$extra_dataobjects); |
|
41 | + $this->assertEquals( |
|
42 | + $excluded, |
|
43 | + array( |
|
44 | + LumberjackStub::class => LumberjackStub::class, |
|
45 | + LumberjackHiddenStub::class => LumberjackHiddenStub::class |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Because we don't know what other test classes are included, we filter to the ones we know |
|
52 | - * and want to test. |
|
53 | - * |
|
54 | - * @param array $classNames |
|
55 | - * @param array $explicitClassNames |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - protected function filteredClassNames($classNames, $explicitClassNames) |
|
59 | - { |
|
60 | - $classNames = array_filter($classNames, function ($value) use ($explicitClassNames) { |
|
61 | - return in_array($value, $explicitClassNames); |
|
62 | - }); |
|
63 | - return $classNames; |
|
64 | - } |
|
50 | + /** |
|
51 | + * Because we don't know what other test classes are included, we filter to the ones we know |
|
52 | + * and want to test. |
|
53 | + * |
|
54 | + * @param array $classNames |
|
55 | + * @param array $explicitClassNames |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + protected function filteredClassNames($classNames, $explicitClassNames) |
|
59 | + { |
|
60 | + $classNames = array_filter($classNames, function ($value) use ($explicitClassNames) { |
|
61 | + return in_array($value, $explicitClassNames); |
|
62 | + }); |
|
63 | + return $classNames; |
|
64 | + } |
|
65 | 65 | } |
@@ -24,24 +24,24 @@ |
||
24 | 24 | **/ |
25 | 25 | class GridFieldConfig_Lumberjack extends GridFieldConfig |
26 | 26 | { |
27 | - /** |
|
28 | - * @param int|null $itemsPerPage |
|
29 | - */ |
|
30 | - public function __construct($itemsPerPage = null) |
|
31 | - { |
|
32 | - parent::__construct($itemsPerPage); |
|
27 | + /** |
|
28 | + * @param int|null $itemsPerPage |
|
29 | + */ |
|
30 | + public function __construct($itemsPerPage = null) |
|
31 | + { |
|
32 | + parent::__construct($itemsPerPage); |
|
33 | 33 | |
34 | - $this->addComponent(new GridFieldButtonRow('before')); |
|
35 | - $this->addComponent(new GridFieldSiteTreeAddNewButton('buttons-before-left')); |
|
36 | - $this->addComponent(new GridFieldToolbarHeader()); |
|
37 | - $this->addComponent(new GridFieldSortableHeader()); |
|
38 | - $this->addComponent(new GridFieldFilterHeader()); |
|
39 | - $this->addComponent(new GridFieldDataColumns()); |
|
40 | - $this->addComponent(new GridFieldSiteTreeEditButton()); |
|
41 | - $this->addComponent(new GridFieldPageCount('toolbar-header-right')); |
|
42 | - $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage)); |
|
43 | - $this->addComponent(new GridFieldSiteTreeState()); |
|
34 | + $this->addComponent(new GridFieldButtonRow('before')); |
|
35 | + $this->addComponent(new GridFieldSiteTreeAddNewButton('buttons-before-left')); |
|
36 | + $this->addComponent(new GridFieldToolbarHeader()); |
|
37 | + $this->addComponent(new GridFieldSortableHeader()); |
|
38 | + $this->addComponent(new GridFieldFilterHeader()); |
|
39 | + $this->addComponent(new GridFieldDataColumns()); |
|
40 | + $this->addComponent(new GridFieldSiteTreeEditButton()); |
|
41 | + $this->addComponent(new GridFieldPageCount('toolbar-header-right')); |
|
42 | + $this->addComponent($pagination = new GridFieldPaginator($itemsPerPage)); |
|
43 | + $this->addComponent(new GridFieldSiteTreeState()); |
|
44 | 44 | |
45 | - $pagination->setThrowExceptionOnBadDataType(true); |
|
46 | - } |
|
45 | + $pagination->setThrowExceptionOnBadDataType(true); |
|
46 | + } |
|
47 | 47 | } |
@@ -14,80 +14,80 @@ |
||
14 | 14 | **/ |
15 | 15 | class GridFieldSiteTreeState implements GridField_ColumnProvider |
16 | 16 | { |
17 | - public function augmentColumns($gridField, &$columns) |
|
18 | - { |
|
19 | - // Ensure Actions always appears as the last column. |
|
20 | - $key = array_search('Actions', $columns); |
|
21 | - if ($key !== false) { |
|
22 | - unset($columns[$key]); |
|
23 | - } |
|
17 | + public function augmentColumns($gridField, &$columns) |
|
18 | + { |
|
19 | + // Ensure Actions always appears as the last column. |
|
20 | + $key = array_search('Actions', $columns); |
|
21 | + if ($key !== false) { |
|
22 | + unset($columns[$key]); |
|
23 | + } |
|
24 | 24 | |
25 | - $columns = array_merge($columns, array( |
|
26 | - 'State', |
|
27 | - 'Actions', |
|
28 | - )); |
|
29 | - } |
|
25 | + $columns = array_merge($columns, array( |
|
26 | + 'State', |
|
27 | + 'Actions', |
|
28 | + )); |
|
29 | + } |
|
30 | 30 | |
31 | - public function getColumnsHandled($gridField) |
|
32 | - { |
|
33 | - return array('State'); |
|
34 | - } |
|
31 | + public function getColumnsHandled($gridField) |
|
32 | + { |
|
33 | + return array('State'); |
|
34 | + } |
|
35 | 35 | |
36 | - public function getColumnContent($gridField, $record, $columnName) |
|
37 | - { |
|
38 | - if ($columnName == 'State') { |
|
39 | - if ($record->hasMethod('isPublished')) { |
|
40 | - $modifiedLabel = ''; |
|
41 | - if ($record->isModifiedOnStage) { |
|
42 | - $modifiedLabel = "<span class='modified'>" . _t('GridFieldSiteTreeState.Modified', 'Modified') . '</span>'; |
|
43 | - } |
|
36 | + public function getColumnContent($gridField, $record, $columnName) |
|
37 | + { |
|
38 | + if ($columnName == 'State') { |
|
39 | + if ($record->hasMethod('isPublished')) { |
|
40 | + $modifiedLabel = ''; |
|
41 | + if ($record->isModifiedOnStage) { |
|
42 | + $modifiedLabel = "<span class='modified'>" . _t('GridFieldSiteTreeState.Modified', 'Modified') . '</span>'; |
|
43 | + } |
|
44 | 44 | |
45 | - $published = $record->isPublished(); |
|
46 | - if (!$published) { |
|
47 | - return _t( |
|
48 | - 'GridFieldSiteTreeState.Draft', |
|
49 | - '<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}', |
|
50 | - 'State for when a post is saved.', |
|
51 | - array( |
|
52 | - 'date' => $record->dbObject('LastEdited')->Nice() |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - return _t( |
|
57 | - 'GridFieldSiteTreeState.Published', |
|
58 | - '<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}', |
|
59 | - 'State for when a post is published.', |
|
60 | - array( |
|
61 | - 'date' => $record->dbObject('LastEdited')->Nice() |
|
62 | - ) |
|
63 | - ) . $modifiedLabel; |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
45 | + $published = $record->isPublished(); |
|
46 | + if (!$published) { |
|
47 | + return _t( |
|
48 | + 'GridFieldSiteTreeState.Draft', |
|
49 | + '<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}', |
|
50 | + 'State for when a post is saved.', |
|
51 | + array( |
|
52 | + 'date' => $record->dbObject('LastEdited')->Nice() |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + return _t( |
|
57 | + 'GridFieldSiteTreeState.Published', |
|
58 | + '<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}', |
|
59 | + 'State for when a post is published.', |
|
60 | + array( |
|
61 | + 'date' => $record->dbObject('LastEdited')->Nice() |
|
62 | + ) |
|
63 | + ) . $modifiedLabel; |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - public function getColumnAttributes($gridField, $record, $columnName) |
|
69 | - { |
|
70 | - if ($columnName == 'State') { |
|
71 | - if ($record->hasMethod('isPublished')) { |
|
72 | - $published = $record->isPublished(); |
|
73 | - if (!$published) { |
|
74 | - $class = 'gridfield-icon draft'; |
|
75 | - } else { |
|
76 | - $class = 'gridfield-icon published'; |
|
77 | - } |
|
78 | - return array('class' => $class); |
|
79 | - } |
|
80 | - } |
|
81 | - return array(); |
|
82 | - } |
|
68 | + public function getColumnAttributes($gridField, $record, $columnName) |
|
69 | + { |
|
70 | + if ($columnName == 'State') { |
|
71 | + if ($record->hasMethod('isPublished')) { |
|
72 | + $published = $record->isPublished(); |
|
73 | + if (!$published) { |
|
74 | + $class = 'gridfield-icon draft'; |
|
75 | + } else { |
|
76 | + $class = 'gridfield-icon published'; |
|
77 | + } |
|
78 | + return array('class' => $class); |
|
79 | + } |
|
80 | + } |
|
81 | + return array(); |
|
82 | + } |
|
83 | 83 | |
84 | - public function getColumnMetaData($gridField, $columnName) |
|
85 | - { |
|
86 | - switch ($columnName) { |
|
87 | - case 'State': |
|
88 | - return array('title' => _t('GridFieldSiteTreeState.StateTitle', 'State', 'Column title for state')); |
|
89 | - default: |
|
90 | - break; |
|
91 | - } |
|
92 | - } |
|
84 | + public function getColumnMetaData($gridField, $columnName) |
|
85 | + { |
|
86 | + switch ($columnName) { |
|
87 | + case 'State': |
|
88 | + return array('title' => _t('GridFieldSiteTreeState.StateTitle', 'State', 'Column title for state')); |
|
89 | + default: |
|
90 | + break; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | if ($record->hasMethod('isPublished')) { |
40 | 40 | $modifiedLabel = ''; |
41 | 41 | if ($record->isModifiedOnStage) { |
42 | - $modifiedLabel = "<span class='modified'>" . _t('GridFieldSiteTreeState.Modified', 'Modified') . '</span>'; |
|
42 | + $modifiedLabel = "<span class='modified'>"._t('GridFieldSiteTreeState.Modified', 'Modified').'</span>'; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $published = $record->isPublished(); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | array( |
61 | 61 | 'date' => $record->dbObject('LastEdited')->Nice() |
62 | 62 | ) |
63 | - ) . $modifiedLabel; |
|
63 | + ).$modifiedLabel; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use SilverStripe\CMS\Controllers\CMSPageAddController; |
6 | 6 | use SilverStripe\CMS\Model\SiteTree; |
7 | 7 | use SilverStripe\Control\Controller; |
8 | -use SilverStripe\Control\Director; |
|
9 | 8 | use SilverStripe\Core\Config\Config; |
10 | 9 | use SilverStripe\Core\Injector\Injector; |
11 | 10 | use SilverStripe\Forms\DropdownField; |
@@ -116,8 +116,8 @@ |
||
116 | 116 | $forTemplate->Fields->push($pageTypes); |
117 | 117 | $forTemplate->Fields->push($addAction); |
118 | 118 | |
119 | - Requirements::css(LUMBERJACK_DIR . '/css/lumberjack.css'); |
|
120 | - Requirements::javascript(LUMBERJACK_DIR . '/javascript/GridField.js'); |
|
119 | + Requirements::css(LUMBERJACK_DIR.'/css/lumberjack.css'); |
|
120 | + Requirements::javascript(LUMBERJACK_DIR.'/javascript/GridField.js'); |
|
121 | 121 | |
122 | 122 | return [$this->targetFragment => $forTemplate->renderWith(__CLASS__)]; |
123 | 123 | } |
@@ -30,143 +30,143 @@ |
||
30 | 30 | * @author Michael Strong <[email protected]> |
31 | 31 | */ |
32 | 32 | class GridFieldSiteTreeAddNewButton extends GridFieldAddNewButton implements |
33 | - GridField_ActionProvider, |
|
34 | - GridFieldComponent |
|
33 | + GridField_ActionProvider, |
|
34 | + GridFieldComponent |
|
35 | 35 | { |
36 | - /** |
|
37 | - * Determine the list of classnames and titles allowed for a given parent object |
|
38 | - * |
|
39 | - * @param SiteTree $parent |
|
40 | - * @return boolean |
|
41 | - */ |
|
42 | - public function getAllowedChildren(SiteTree $parent = null) |
|
43 | - { |
|
44 | - if (!$parent || !$parent->canAddChildren()) { |
|
45 | - return array(); |
|
46 | - } |
|
47 | - |
|
48 | - $nonHiddenPageTypes = SiteTree::page_type_classes(); |
|
49 | - $allowedChildren = $parent->allowedChildren(); |
|
50 | - $children = array(); |
|
51 | - foreach ($allowedChildren as $class) { |
|
52 | - if (Config::inst()->get($class, 'show_in_sitetree') === false) { |
|
53 | - $instance = Injector::inst()->get($class); |
|
54 | - // Note: Second argument to SiteTree::canCreate will support inherited permissions |
|
55 | - // post 3.1.12, and will default to the old permission model in 3.1.11 or below |
|
56 | - // See http://docs.silverstripe.org/en/changelogs/3.1.11 |
|
57 | - if ($instance->canCreate(null, array('Parent' => $parent)) && in_array($class, $nonHiddenPageTypes)) { |
|
58 | - $children[$class] = $instance->i18n_singular_name(); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
62 | - return $children; |
|
63 | - } |
|
64 | - |
|
65 | - public function getHTMLFragments($gridField) |
|
66 | - { |
|
67 | - $state = $gridField->State->GridFieldSiteTreeAddNewButton; |
|
68 | - |
|
69 | - $parent = SiteTree::get()->byId(Controller::curr()->currentPageID()); |
|
70 | - |
|
71 | - if ($parent) { |
|
72 | - $state->currentPageID = $parent->ID; |
|
73 | - } |
|
74 | - |
|
75 | - $children = $this->getAllowedChildren($parent); |
|
76 | - if (empty($children)) { |
|
77 | - return array(); |
|
78 | - } elseif (count($children) > 1) { |
|
79 | - $pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild()); |
|
80 | - $pageTypes |
|
81 | - ->setFieldHolderTemplate('GridFieldSiteTreeAddNewButton_holder') |
|
82 | - ->addExtraClass('gridfield-dropdown no-change-track'); |
|
83 | - |
|
84 | - $state->pageType = $parent->defaultChild(); |
|
85 | - |
|
86 | - if (!$this->buttonName) { |
|
87 | - $this->buttonName = _t( |
|
88 | - 'GridFieldSiteTreeAddNewButton.AddMultipleOptions', |
|
89 | - 'Add new', |
|
90 | - 'Add button text for multiple options.' |
|
91 | - ); |
|
92 | - } |
|
93 | - } else { |
|
94 | - $keys = array_keys($children); |
|
95 | - $pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]); |
|
96 | - |
|
97 | - $state->pageType = $keys[0]; |
|
98 | - |
|
99 | - if (!$this->buttonName) { |
|
100 | - $this->buttonName = _t( |
|
101 | - 'GridFieldSiteTreeAddNewButton.Add', |
|
102 | - 'Add new {name}', |
|
103 | - 'Add button text for a single option.', |
|
104 | - ['name' => $children[$keys[0]]] |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - $addAction = GridField_FormAction::create($gridField, 'add', $this->buttonName, 'add', 'add'); |
|
110 | - $addAction |
|
111 | - ->setAttribute('data-icon', 'add') |
|
112 | - ->addExtraClass('no-ajax btn btn-primary font-icon-plus'); |
|
113 | - |
|
114 | - $forTemplate = ArrayData::create([]); |
|
115 | - $forTemplate->Fields = ArrayList::create(); |
|
116 | - $forTemplate->Fields->push($pageTypes); |
|
117 | - $forTemplate->Fields->push($addAction); |
|
118 | - |
|
119 | - Requirements::css(LUMBERJACK_DIR . '/css/lumberjack.css'); |
|
120 | - Requirements::javascript(LUMBERJACK_DIR . '/javascript/GridField.js'); |
|
121 | - |
|
122 | - return [$this->targetFragment => $forTemplate->renderWith(__CLASS__)]; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Provide actions to this component. |
|
127 | - * |
|
128 | - * @param GridField $gridField |
|
129 | - * @return array |
|
130 | - **/ |
|
131 | - public function getActions($gridField) |
|
132 | - { |
|
133 | - return array('add'); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Handles the add action, but only acts as a wrapper for {@link CMSPageAddController::doAdd()} |
|
138 | - * |
|
139 | - * @param GridField $gridField |
|
140 | - * @param string $actionName |
|
141 | - * @param mixed $arguments |
|
142 | - * @param array $data |
|
143 | - **/ |
|
144 | - public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
|
145 | - { |
|
146 | - if ($actionName == 'add') { |
|
147 | - $tmpData = json_decode($data['ChildPages']['GridState'], true); |
|
148 | - /** @skipUpgrade */ |
|
149 | - $tmpData = $tmpData['GridFieldSiteTreeAddNewButton']; |
|
150 | - |
|
151 | - $data = array( |
|
152 | - 'ParentID' => $tmpData['currentPageID'], |
|
153 | - 'PageType' => $tmpData['pageType'] |
|
154 | - ); |
|
155 | - |
|
156 | - $controller = Injector::inst()->create(CMSPageAddController::class); |
|
157 | - |
|
158 | - $form = $controller->AddForm(); |
|
159 | - $form->loadDataFrom($data); |
|
160 | - |
|
161 | - $controller->doAdd($data, $form); |
|
162 | - $response = $controller->getResponseNegotiator()->getResponse(); |
|
163 | - |
|
164 | - // Get the current record |
|
165 | - $record = SiteTree::get()->byId($controller->currentPageID()); |
|
166 | - if ($record) { |
|
167 | - $response->redirect($record->CMSEditLink(), 301); |
|
168 | - } |
|
169 | - return $response; |
|
170 | - } |
|
171 | - } |
|
36 | + /** |
|
37 | + * Determine the list of classnames and titles allowed for a given parent object |
|
38 | + * |
|
39 | + * @param SiteTree $parent |
|
40 | + * @return boolean |
|
41 | + */ |
|
42 | + public function getAllowedChildren(SiteTree $parent = null) |
|
43 | + { |
|
44 | + if (!$parent || !$parent->canAddChildren()) { |
|
45 | + return array(); |
|
46 | + } |
|
47 | + |
|
48 | + $nonHiddenPageTypes = SiteTree::page_type_classes(); |
|
49 | + $allowedChildren = $parent->allowedChildren(); |
|
50 | + $children = array(); |
|
51 | + foreach ($allowedChildren as $class) { |
|
52 | + if (Config::inst()->get($class, 'show_in_sitetree') === false) { |
|
53 | + $instance = Injector::inst()->get($class); |
|
54 | + // Note: Second argument to SiteTree::canCreate will support inherited permissions |
|
55 | + // post 3.1.12, and will default to the old permission model in 3.1.11 or below |
|
56 | + // See http://docs.silverstripe.org/en/changelogs/3.1.11 |
|
57 | + if ($instance->canCreate(null, array('Parent' => $parent)) && in_array($class, $nonHiddenPageTypes)) { |
|
58 | + $children[$class] = $instance->i18n_singular_name(); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | + return $children; |
|
63 | + } |
|
64 | + |
|
65 | + public function getHTMLFragments($gridField) |
|
66 | + { |
|
67 | + $state = $gridField->State->GridFieldSiteTreeAddNewButton; |
|
68 | + |
|
69 | + $parent = SiteTree::get()->byId(Controller::curr()->currentPageID()); |
|
70 | + |
|
71 | + if ($parent) { |
|
72 | + $state->currentPageID = $parent->ID; |
|
73 | + } |
|
74 | + |
|
75 | + $children = $this->getAllowedChildren($parent); |
|
76 | + if (empty($children)) { |
|
77 | + return array(); |
|
78 | + } elseif (count($children) > 1) { |
|
79 | + $pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild()); |
|
80 | + $pageTypes |
|
81 | + ->setFieldHolderTemplate('GridFieldSiteTreeAddNewButton_holder') |
|
82 | + ->addExtraClass('gridfield-dropdown no-change-track'); |
|
83 | + |
|
84 | + $state->pageType = $parent->defaultChild(); |
|
85 | + |
|
86 | + if (!$this->buttonName) { |
|
87 | + $this->buttonName = _t( |
|
88 | + 'GridFieldSiteTreeAddNewButton.AddMultipleOptions', |
|
89 | + 'Add new', |
|
90 | + 'Add button text for multiple options.' |
|
91 | + ); |
|
92 | + } |
|
93 | + } else { |
|
94 | + $keys = array_keys($children); |
|
95 | + $pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]); |
|
96 | + |
|
97 | + $state->pageType = $keys[0]; |
|
98 | + |
|
99 | + if (!$this->buttonName) { |
|
100 | + $this->buttonName = _t( |
|
101 | + 'GridFieldSiteTreeAddNewButton.Add', |
|
102 | + 'Add new {name}', |
|
103 | + 'Add button text for a single option.', |
|
104 | + ['name' => $children[$keys[0]]] |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + $addAction = GridField_FormAction::create($gridField, 'add', $this->buttonName, 'add', 'add'); |
|
110 | + $addAction |
|
111 | + ->setAttribute('data-icon', 'add') |
|
112 | + ->addExtraClass('no-ajax btn btn-primary font-icon-plus'); |
|
113 | + |
|
114 | + $forTemplate = ArrayData::create([]); |
|
115 | + $forTemplate->Fields = ArrayList::create(); |
|
116 | + $forTemplate->Fields->push($pageTypes); |
|
117 | + $forTemplate->Fields->push($addAction); |
|
118 | + |
|
119 | + Requirements::css(LUMBERJACK_DIR . '/css/lumberjack.css'); |
|
120 | + Requirements::javascript(LUMBERJACK_DIR . '/javascript/GridField.js'); |
|
121 | + |
|
122 | + return [$this->targetFragment => $forTemplate->renderWith(__CLASS__)]; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Provide actions to this component. |
|
127 | + * |
|
128 | + * @param GridField $gridField |
|
129 | + * @return array |
|
130 | + **/ |
|
131 | + public function getActions($gridField) |
|
132 | + { |
|
133 | + return array('add'); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Handles the add action, but only acts as a wrapper for {@link CMSPageAddController::doAdd()} |
|
138 | + * |
|
139 | + * @param GridField $gridField |
|
140 | + * @param string $actionName |
|
141 | + * @param mixed $arguments |
|
142 | + * @param array $data |
|
143 | + **/ |
|
144 | + public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
|
145 | + { |
|
146 | + if ($actionName == 'add') { |
|
147 | + $tmpData = json_decode($data['ChildPages']['GridState'], true); |
|
148 | + /** @skipUpgrade */ |
|
149 | + $tmpData = $tmpData['GridFieldSiteTreeAddNewButton']; |
|
150 | + |
|
151 | + $data = array( |
|
152 | + 'ParentID' => $tmpData['currentPageID'], |
|
153 | + 'PageType' => $tmpData['pageType'] |
|
154 | + ); |
|
155 | + |
|
156 | + $controller = Injector::inst()->create(CMSPageAddController::class); |
|
157 | + |
|
158 | + $form = $controller->AddForm(); |
|
159 | + $form->loadDataFrom($data); |
|
160 | + |
|
161 | + $controller->doAdd($data, $form); |
|
162 | + $response = $controller->getResponseNegotiator()->getResponse(); |
|
163 | + |
|
164 | + // Get the current record |
|
165 | + $record = SiteTree::get()->byId($controller->currentPageID()); |
|
166 | + if ($record) { |
|
167 | + $response->redirect($record->CMSEditLink(), 301); |
|
168 | + } |
|
169 | + return $response; |
|
170 | + } |
|
171 | + } |
|
172 | 172 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | * Provide actions to this component. |
127 | 127 | * |
128 | 128 | * @param GridField $gridField |
129 | - * @return array |
|
129 | + * @return string[] |
|
130 | 130 | **/ |
131 | 131 | public function getActions($gridField) |
132 | 132 | { |
@@ -17,21 +17,21 @@ |
||
17 | 17 | **/ |
18 | 18 | class GridFieldSiteTreeEditButton extends GridFieldEditButton |
19 | 19 | { |
20 | - /** |
|
21 | - * @param GridField $gridField |
|
22 | - * @param DataObject $record |
|
23 | - * @param string $columnName |
|
24 | - * @return string - the HTML for the column |
|
25 | - */ |
|
26 | - public function getColumnContent($gridField, $record, $columnName) |
|
27 | - { |
|
28 | - // No permission checks - handled through GridFieldDetailForm |
|
29 | - // which can make the form readonly if no edit permissions are available. |
|
20 | + /** |
|
21 | + * @param GridField $gridField |
|
22 | + * @param DataObject $record |
|
23 | + * @param string $columnName |
|
24 | + * @return string - the HTML for the column |
|
25 | + */ |
|
26 | + public function getColumnContent($gridField, $record, $columnName) |
|
27 | + { |
|
28 | + // No permission checks - handled through GridFieldDetailForm |
|
29 | + // which can make the form readonly if no edit permissions are available. |
|
30 | 30 | |
31 | - $data = ArrayData::create( |
|
32 | - ['Link' => $record->CMSEditLink()] |
|
33 | - ); |
|
31 | + $data = ArrayData::create( |
|
32 | + ['Link' => $record->CMSEditLink()] |
|
33 | + ); |
|
34 | 34 | |
35 | - return $data->renderWith(GridFieldEditButton::class); |
|
36 | - } |
|
35 | + return $data->renderWith(GridFieldEditButton::class); |
|
36 | + } |
|
37 | 37 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | |
7 | 7 | class LumberjackShownStub extends LumberjackHiddenStub implements TestOnly |
8 | 8 | { |
9 | - private static $show_in_sitetree = true; |
|
9 | + private static $show_in_sitetree = true; |
|
10 | 10 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | |
7 | 7 | class LumberjackHiddenStub extends LumberjackStub implements TestOnly |
8 | 8 | { |
9 | - private static $show_in_sitetree = false; |
|
9 | + private static $show_in_sitetree = false; |
|
10 | 10 | } |
@@ -8,5 +8,5 @@ |
||
8 | 8 | |
9 | 9 | class LumberjackStub extends SiteTree implements TestOnly |
10 | 10 | { |
11 | - private static $extensions = [Lumberjack::class]; |
|
11 | + private static $extensions = [Lumberjack::class]; |
|
12 | 12 | } |
@@ -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 | } |