@@ -3,11 +3,9 @@ |
||
3 | 3 | namespace SheaDawson\Blocks; |
4 | 4 | |
5 | 5 | use SilverStripe\ORM\ArrayLib; |
6 | -use SilverStripe\SiteConfig\SiteConfig; |
|
7 | 6 | use SilverStripe\Core\Config\Config; |
8 | 7 | use SilverStripe\Core\ClassInfo; |
9 | 8 | use SilverStripe\Forms\FormField; |
10 | -use SilverStripe\View\SSViewer; |
|
11 | 9 | use SilverStripe\View\ViewableData; |
12 | 10 | |
13 | 11 | /** |
@@ -17,187 +17,187 @@ |
||
17 | 17 | */ |
18 | 18 | class BlockManager extends ViewableData |
19 | 19 | { |
20 | - /** |
|
21 | - * Use default ContentBlock class. |
|
22 | - * |
|
23 | - * @var bool |
|
24 | - **/ |
|
25 | - private static $use_default_blocks = true; |
|
26 | - |
|
27 | - /** |
|
28 | - * Show a block area preview button in CMS |
|
29 | - * |
|
30 | - * @var bool |
|
31 | - **/ |
|
32 | - private static $block_area_preview = true; |
|
33 | - |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - parent::__construct(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets an array of all areas defined for blocks. |
|
41 | - * |
|
42 | - * @param bool $keyAsValue |
|
43 | - * |
|
44 | - * @return array $areas |
|
45 | - **/ |
|
46 | - public function getAreas($keyAsValue = true) |
|
47 | - { |
|
48 | - $areas = $this->config()->get('areas'); |
|
49 | - |
|
50 | - $areas = $keyAsValue ? ArrayLib::valuekey(array_keys($areas)) : $areas; |
|
51 | - if (count($areas)) { |
|
52 | - foreach ($areas as $k => $v) { |
|
53 | - $areas[$k] = $keyAsValue ? FormField::name_to_label($k) : $v; |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - return $areas; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Gets an array of all areas defined that are compatible with pages of type $class. |
|
62 | - * |
|
63 | - * @param string $class |
|
64 | - * |
|
65 | - * @return array $areas |
|
66 | - **/ |
|
67 | - public function getAreasForPageType($class) |
|
68 | - { |
|
69 | - $areas = $this->getAreas(false); |
|
70 | - |
|
71 | - if (!$areas) { |
|
72 | - return false; |
|
73 | - } |
|
74 | - |
|
75 | - foreach ($areas as $area => $config) { |
|
76 | - if (!is_array($config)) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if (isset($config['except'])) { |
|
81 | - $except = $config['except']; |
|
82 | - if (is_array($except) |
|
83 | - ? in_array($class, $except) |
|
84 | - : $except == $class |
|
85 | - ) { |
|
86 | - unset($areas[$area]); |
|
87 | - continue; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - if (isset($config['only'])) { |
|
92 | - $only = $config['only']; |
|
93 | - if (is_array($only) |
|
94 | - ? !in_array($class, $only) |
|
95 | - : $only != $class |
|
96 | - ) { |
|
97 | - unset($areas[$area]); |
|
98 | - continue; |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - if (count($areas)) { |
|
104 | - foreach ($areas as $k => $v) { |
|
105 | - $areas[$k] = _t('Block.BlockAreaName.'.$k, FormField::name_to_label($k)); |
|
106 | - } |
|
107 | - |
|
108 | - return $areas; |
|
109 | - } else { |
|
110 | - return $areas; |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - public function getBlockClasses() |
|
115 | - { |
|
116 | - $classes = ArrayLib::valuekey(ClassInfo::subclassesFor("SheaDawson\Blocks\model\Block")); |
|
117 | - array_shift($classes); |
|
118 | - foreach ($classes as $k => $v) { |
|
119 | - $classes[$k] = singleton($k)->singular_name(); |
|
120 | - } |
|
121 | - |
|
122 | - $config = $this->config()->get('options'); |
|
123 | - |
|
124 | - if (isset($config['use_default_blocks']) && !$config['use_default_blocks']) { |
|
125 | - unset($classes['ContentBlock']); |
|
126 | - } else if (!$config['use_default_blocks']) { |
|
127 | - unset($classes['ContentBlock']); |
|
128 | - } |
|
129 | - |
|
130 | - $disabledArr = Config::inst()->get("BlockManager", 'disabled_blocks') ? Config::inst()->get("BlockManager", 'disabled_blocks') : []; |
|
131 | - if (isset($config['disabled_blocks'])) { |
|
132 | - $disabledArr = array_merge($disabledArr, $config['disabled_blocks']); |
|
133 | - } |
|
134 | - if (count($disabledArr)) { |
|
135 | - foreach ($disabledArr as $k => $v) { |
|
136 | - unset($classes[$v]); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $classes; |
|
141 | - } |
|
142 | - |
|
143 | - /* |
|
20 | + /** |
|
21 | + * Use default ContentBlock class. |
|
22 | + * |
|
23 | + * @var bool |
|
24 | + **/ |
|
25 | + private static $use_default_blocks = true; |
|
26 | + |
|
27 | + /** |
|
28 | + * Show a block area preview button in CMS |
|
29 | + * |
|
30 | + * @var bool |
|
31 | + **/ |
|
32 | + private static $block_area_preview = true; |
|
33 | + |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets an array of all areas defined for blocks. |
|
41 | + * |
|
42 | + * @param bool $keyAsValue |
|
43 | + * |
|
44 | + * @return array $areas |
|
45 | + **/ |
|
46 | + public function getAreas($keyAsValue = true) |
|
47 | + { |
|
48 | + $areas = $this->config()->get('areas'); |
|
49 | + |
|
50 | + $areas = $keyAsValue ? ArrayLib::valuekey(array_keys($areas)) : $areas; |
|
51 | + if (count($areas)) { |
|
52 | + foreach ($areas as $k => $v) { |
|
53 | + $areas[$k] = $keyAsValue ? FormField::name_to_label($k) : $v; |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + return $areas; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Gets an array of all areas defined that are compatible with pages of type $class. |
|
62 | + * |
|
63 | + * @param string $class |
|
64 | + * |
|
65 | + * @return array $areas |
|
66 | + **/ |
|
67 | + public function getAreasForPageType($class) |
|
68 | + { |
|
69 | + $areas = $this->getAreas(false); |
|
70 | + |
|
71 | + if (!$areas) { |
|
72 | + return false; |
|
73 | + } |
|
74 | + |
|
75 | + foreach ($areas as $area => $config) { |
|
76 | + if (!is_array($config)) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if (isset($config['except'])) { |
|
81 | + $except = $config['except']; |
|
82 | + if (is_array($except) |
|
83 | + ? in_array($class, $except) |
|
84 | + : $except == $class |
|
85 | + ) { |
|
86 | + unset($areas[$area]); |
|
87 | + continue; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + if (isset($config['only'])) { |
|
92 | + $only = $config['only']; |
|
93 | + if (is_array($only) |
|
94 | + ? !in_array($class, $only) |
|
95 | + : $only != $class |
|
96 | + ) { |
|
97 | + unset($areas[$area]); |
|
98 | + continue; |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + if (count($areas)) { |
|
104 | + foreach ($areas as $k => $v) { |
|
105 | + $areas[$k] = _t('Block.BlockAreaName.'.$k, FormField::name_to_label($k)); |
|
106 | + } |
|
107 | + |
|
108 | + return $areas; |
|
109 | + } else { |
|
110 | + return $areas; |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + public function getBlockClasses() |
|
115 | + { |
|
116 | + $classes = ArrayLib::valuekey(ClassInfo::subclassesFor("SheaDawson\Blocks\model\Block")); |
|
117 | + array_shift($classes); |
|
118 | + foreach ($classes as $k => $v) { |
|
119 | + $classes[$k] = singleton($k)->singular_name(); |
|
120 | + } |
|
121 | + |
|
122 | + $config = $this->config()->get('options'); |
|
123 | + |
|
124 | + if (isset($config['use_default_blocks']) && !$config['use_default_blocks']) { |
|
125 | + unset($classes['ContentBlock']); |
|
126 | + } else if (!$config['use_default_blocks']) { |
|
127 | + unset($classes['ContentBlock']); |
|
128 | + } |
|
129 | + |
|
130 | + $disabledArr = Config::inst()->get("BlockManager", 'disabled_blocks') ? Config::inst()->get("BlockManager", 'disabled_blocks') : []; |
|
131 | + if (isset($config['disabled_blocks'])) { |
|
132 | + $disabledArr = array_merge($disabledArr, $config['disabled_blocks']); |
|
133 | + } |
|
134 | + if (count($disabledArr)) { |
|
135 | + foreach ($disabledArr as $k => $v) { |
|
136 | + unset($classes[$v]); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $classes; |
|
141 | + } |
|
142 | + |
|
143 | + /* |
|
144 | 144 | * Usage of BlockSets configurable from yaml |
145 | 145 | */ |
146 | - public function getUseBlockSets() |
|
147 | - { |
|
148 | - $config = $this->config()->get('options'); |
|
146 | + public function getUseBlockSets() |
|
147 | + { |
|
148 | + $config = $this->config()->get('options'); |
|
149 | 149 | |
150 | - return isset($config['use_blocksets']) ? $config['use_blocksets'] : true; |
|
151 | - } |
|
150 | + return isset($config['use_blocksets']) ? $config['use_blocksets'] : true; |
|
151 | + } |
|
152 | 152 | |
153 | - /* |
|
153 | + /* |
|
154 | 154 | * Exclusion of blocks from page types defined in yaml |
155 | 155 | */ |
156 | - public function getExcludeFromPageTypes() |
|
157 | - { |
|
158 | - $config = $this->config()->get('options'); |
|
156 | + public function getExcludeFromPageTypes() |
|
157 | + { |
|
158 | + $config = $this->config()->get('options'); |
|
159 | 159 | |
160 | - return isset($config['exclude_from_page_types']) ? $config['exclude_from_page_types'] : []; |
|
161 | - } |
|
160 | + return isset($config['exclude_from_page_types']) ? $config['exclude_from_page_types'] : []; |
|
161 | + } |
|
162 | 162 | |
163 | - /* |
|
163 | + /* |
|
164 | 164 | * getWhiteListedPageTypes optionally configured by the developer |
165 | 165 | */ |
166 | - public function getWhiteListedPageTypes() |
|
167 | - { |
|
168 | - $config = $this->config()->get('options'); |
|
169 | - return isset($config['pagetype_whitelist']) ? $config['pagetype_whitelist'] : []; |
|
170 | - } |
|
166 | + public function getWhiteListedPageTypes() |
|
167 | + { |
|
168 | + $config = $this->config()->get('options'); |
|
169 | + return isset($config['pagetype_whitelist']) ? $config['pagetype_whitelist'] : []; |
|
170 | + } |
|
171 | 171 | |
172 | - /* |
|
172 | + /* |
|
173 | 173 | * getBlackListedPageTypes optionally configured by the developer |
174 | 174 | * Includes blacklisted page types defined in the old exclude_from_page_types array |
175 | 175 | */ |
176 | - public function getBlackListedPageTypes() |
|
177 | - { |
|
178 | - $config = $this->config()->get('options'); |
|
179 | - $legacy = isset($config['exclude_from_page_types']) ? $config['exclude_from_page_types'] : []; |
|
180 | - $current = isset($config['pagetype_blacklist']) ? $config['pagetype_blacklist'] : []; |
|
181 | - return array_merge($legacy, $current); |
|
182 | - } |
|
183 | - |
|
184 | - /* |
|
176 | + public function getBlackListedPageTypes() |
|
177 | + { |
|
178 | + $config = $this->config()->get('options'); |
|
179 | + $legacy = isset($config['exclude_from_page_types']) ? $config['exclude_from_page_types'] : []; |
|
180 | + $current = isset($config['pagetype_blacklist']) ? $config['pagetype_blacklist'] : []; |
|
181 | + return array_merge($legacy, $current); |
|
182 | + } |
|
183 | + |
|
184 | + /* |
|
185 | 185 | * Usage of extra css classes configurable from yaml |
186 | 186 | */ |
187 | - public function getUseExtraCSSClasses() |
|
188 | - { |
|
189 | - $config = $this->config()->get('options'); |
|
187 | + public function getUseExtraCSSClasses() |
|
188 | + { |
|
189 | + $config = $this->config()->get('options'); |
|
190 | 190 | |
191 | - return isset($config['use_extra_css_classes']) ? $config['use_extra_css_classes'] : false; |
|
192 | - } |
|
191 | + return isset($config['use_extra_css_classes']) ? $config['use_extra_css_classes'] : false; |
|
192 | + } |
|
193 | 193 | |
194 | - /* |
|
194 | + /* |
|
195 | 195 | * Prefix for the default CSSClasses |
196 | 196 | */ |
197 | - public function getPrefixDefaultCSSClasses() |
|
198 | - { |
|
199 | - $config = $this->config()->get('options'); |
|
197 | + public function getPrefixDefaultCSSClasses() |
|
198 | + { |
|
199 | + $config = $this->config()->get('options'); |
|
200 | 200 | |
201 | - return isset($config['prefix_default_css_classes']) ? $config['prefix_default_css_classes'] : false; |
|
202 | - } |
|
201 | + return isset($config['prefix_default_css_classes']) ? $config['prefix_default_css_classes'] : false; |
|
202 | + } |
|
203 | 203 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * @return Form |
|
51 | + * @return \SilverStripe\Forms\Form |
|
52 | 52 | **/ |
53 | 53 | public function getEditForm($id = null, $fields = null) |
54 | 54 | { |
@@ -267,6 +267,7 @@ |
||
267 | 267 | /** |
268 | 268 | * Get all Blocks from BlockSets that apply to this page. |
269 | 269 | * |
270 | + * @param string $area |
|
270 | 271 | * @return ArrayList |
271 | 272 | * */ |
272 | 273 | public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false) |
@@ -3,7 +3,6 @@ discard block |
||
3 | 3 | namespace SheaDawson\Blocks\Extensions; |
4 | 4 | |
5 | 5 | use SheaDawson\Blocks\Model\Block; |
6 | -use SheaDawson\Blocks\Model\Blockset; |
|
7 | 6 | use SheaDawson\Blocks\BlockManager; |
8 | 7 | use SheaDawson\Blocks\Forms\GridFieldConfigBlockManager; |
9 | 8 | use SilverStripe\CMS\Model\SiteTreeExtension; |
@@ -18,7 +17,6 @@ discard block |
||
18 | 17 | use SilverStripe\ORM\ArrayList; |
19 | 18 | use SilverStripe\Security\Permission; |
20 | 19 | use SilverStripe\Control\Controller; |
21 | -use SilverStripeAustralia\GridFieldExtensions\GridFieldOrderableRows; |
|
22 | 20 | |
23 | 21 | /** |
24 | 22 | * BlocksSiteTreeExtension. |
@@ -27,321 +27,321 @@ |
||
27 | 27 | */ |
28 | 28 | class BlocksSiteTreeExtension extends SiteTreeExtension |
29 | 29 | { |
30 | - private static $db = [ |
|
31 | - 'InheritBlockSets' => 'Boolean', |
|
32 | - ]; |
|
33 | - |
|
34 | - private static $many_many = [ |
|
35 | - "Blocks" => Block::class, |
|
36 | - "DisabledBlocks" => Block::class, |
|
37 | - ]; |
|
38 | - |
|
39 | - public static $many_many_extraFields = [ |
|
40 | - 'Blocks' => [ |
|
41 | - 'Sort' => 'Int', |
|
42 | - 'BlockArea' => 'Varchar', |
|
43 | - ], |
|
44 | - ]; |
|
45 | - |
|
46 | - private static $defaults = [ |
|
47 | - 'InheritBlockSets' => 1, |
|
48 | - ]; |
|
49 | - |
|
50 | - private static $dependencies = [ |
|
51 | - 'blockManager' => '%$blockManager', |
|
52 | - ]; |
|
53 | - |
|
54 | - public $blockManager; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Check if the Blocks CMSFields should be displayed for this Page |
|
59 | - * |
|
60 | - * @return boolean |
|
61 | - **/ |
|
62 | - public function showBlocksFields() |
|
63 | - { |
|
64 | - $whiteList = $this->blockManager->getWhiteListedPageTypes(); |
|
65 | - $blackList = $this->blockManager->getBlackListedPageTypes(); |
|
66 | - |
|
67 | - if (in_array($this->owner->ClassName, $blackList)) { |
|
68 | - return false; |
|
69 | - } |
|
70 | - |
|
71 | - if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) { |
|
72 | - return false; |
|
73 | - } |
|
74 | - |
|
75 | - if (!Permission::check('BLOCK_EDIT')) { |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - return true; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Block manager for Pages. |
|
84 | - * */ |
|
85 | - public function updateCMSFields(FieldList $fields) |
|
86 | - { |
|
87 | - if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) { |
|
88 | - return; |
|
89 | - } |
|
90 | - |
|
91 | - $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); |
|
92 | - |
|
93 | - if ($areas && count($areas)) { |
|
94 | - $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks'))); |
|
95 | - if (BlockManager::config()->get('block_area_preview')) { |
|
96 | - $fields->addFieldToTab('Root.Blocks', |
|
97 | - LiteralField::create('PreviewLink', $this->areasPreviewButton())); |
|
98 | - } |
|
99 | - |
|
100 | - // Blocks related directly to this Page |
|
101 | - $gridConfig = GridFieldConfigBlockManager::create(true, true, true, true) |
|
102 | - ->addExisting($this->owner->class) |
|
103 | - //->addBulkEditing() |
|
104 | - // ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete. |
|
105 | - ; |
|
106 | - |
|
107 | - |
|
108 | - // TODO it seems this sort is not being applied... |
|
109 | - $gridSource = $this->owner->Blocks(); |
|
110 | - // ->sort(array( |
|
111 | - // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', |
|
112 | - // 'SiteTree_Blocks.Sort' => 'ASC', |
|
113 | - // 'Name' => 'ASC' |
|
114 | - // )); |
|
115 | - |
|
116 | - $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); |
|
117 | - |
|
118 | - |
|
119 | - // Blocks inherited from BlockSets |
|
120 | - if ($this->blockManager->getUseBlockSets()) { |
|
121 | - $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); |
|
122 | - |
|
123 | - if ($inheritedBlocks->count()) { |
|
124 | - $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); |
|
125 | - |
|
126 | - if ($activeInherited->count()) { |
|
127 | - $fields->addFieldsToTab('Root.Blocks', [ |
|
128 | - GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, |
|
129 | - GridFieldConfigBlockManager::create(false, false, false)), |
|
130 | - LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'), |
|
131 | - ]); |
|
132 | - } |
|
133 | - |
|
134 | - $fields->addFieldToTab('Root.Blocks', |
|
135 | - ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), |
|
136 | - $inheritedBlocks->map('ID', 'Title'), null, null, true) |
|
137 | - ->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')) |
|
138 | - ); |
|
139 | - } else { |
|
140 | - $fields->addFieldToTab('Root.Blocks', |
|
141 | - ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), |
|
142 | - _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.'))); |
|
143 | - } |
|
144 | - |
|
145 | - $fields->addFieldToTab('Root.Blocks', |
|
146 | - CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets'))); |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Called from templates to get rendered blocks for the given area. |
|
153 | - * |
|
154 | - * @param string $area |
|
155 | - * @param int $limit Limit the items to this number, or null for no limit |
|
156 | - */ |
|
157 | - public function BlockArea($area, $limit = null) |
|
158 | - { |
|
159 | - if ($this->owner->ID <= 0) { |
|
160 | - return; |
|
161 | - } // blocks break on fake pages ie Security/login |
|
162 | - |
|
163 | - $list = $this->getBlockList($area); |
|
164 | - |
|
165 | - foreach ($list as $block) { |
|
166 | - if (!$block->canView()) { |
|
167 | - $list->remove($block); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - if ($limit !== null) { |
|
172 | - $list = $list->limit($limit); |
|
173 | - } |
|
174 | - |
|
175 | - $data = []; |
|
176 | - $data['HasBlockArea'] = ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) || $list->Count() > 0; |
|
177 | - $data['BlockArea'] = $list; |
|
178 | - $data['AreaID'] = $area; |
|
179 | - |
|
180 | - $data = $this->owner->customise($data); |
|
181 | - |
|
182 | - $template = ['BlockArea_'.$area]; |
|
183 | - |
|
184 | - if (SSViewer::hasTemplate($template)) { |
|
185 | - return $data->renderWith($template); |
|
186 | - } else { |
|
187 | - return $data->renderWith('BlockArea'); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - public function HasBlockArea($area) |
|
192 | - { |
|
193 | - if ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) { |
|
194 | - return true; |
|
195 | - } |
|
196 | - |
|
197 | - $list = $this->getBlockList($area); |
|
198 | - |
|
199 | - foreach ($list as $block) { |
|
200 | - if (!$block->canView()) { |
|
201 | - $list->remove($block); |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - return $list->Count() > 0; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get a merged list of all blocks on this page and ones inherited from BlockSets. |
|
210 | - * |
|
211 | - * @param string|null $area filter by block area |
|
212 | - * @param bool $includeDisabled Include blocks that have been explicitly excluded from this page |
|
213 | - * i.e. blocks from block sets added to the "disable inherited blocks" list |
|
214 | - * |
|
215 | - * @return ArrayList |
|
216 | - * */ |
|
217 | - public function getBlockList($area = null, $includeDisabled = false) |
|
218 | - { |
|
219 | - $includeSets = $this->blockManager->getUseBlockSets() && $this->owner->InheritBlockSets; |
|
220 | - $blocks = ArrayList::create(); |
|
221 | - |
|
222 | - // get blocks directly linked to this page |
|
223 | - $nativeBlocks = $this->owner->Blocks()->sort('Sort'); |
|
224 | - if ($area) { |
|
225 | - $nativeBlocks = $nativeBlocks->filter('BlockArea', $area); |
|
226 | - } |
|
227 | - |
|
228 | - if ($nativeBlocks->count()) { |
|
229 | - foreach ($nativeBlocks as $block) { |
|
230 | - $blocks->add($block); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - // get blocks from BlockSets |
|
235 | - if ($includeSets) { |
|
236 | - $blocksFromSets = $this->getBlocksFromAppliedBlockSets($area, $includeDisabled); |
|
237 | - if ($blocksFromSets->count()) { |
|
238 | - // merge set sources |
|
239 | - foreach ($blocksFromSets as $block) { |
|
240 | - if (!$blocks->find('ID', $block->ID)) { |
|
241 | - if ($block->AboveOrBelow == 'Above') { |
|
242 | - $blocks->unshift($block); |
|
243 | - } else { |
|
244 | - $blocks->push($block); |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - return $blocks; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Get Any BlockSets that apply to this page. |
|
256 | - * |
|
257 | - * @return ArrayList |
|
258 | - * */ |
|
259 | - public function getAppliedSets() |
|
260 | - { |
|
261 | - $list = ArrayList::create(); |
|
262 | - if (!$this->owner->InheritBlockSets) { |
|
263 | - return $list; |
|
264 | - } |
|
265 | - |
|
266 | - $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')"); |
|
267 | - $ancestors = $this->owner->getAncestors()->column('ID'); |
|
268 | - |
|
269 | - foreach ($sets as $set) { |
|
270 | - $restrictedToParerentIDs = $set->PageParents()->column('ID'); |
|
271 | - if (count($restrictedToParerentIDs)) { |
|
272 | - // check whether the set should include selected parent, in which case check whether |
|
273 | - // it was in the restricted parents list. If it's not, or if include parentpage |
|
274 | - // wasn't selected, we check the ancestors of this page. |
|
275 | - if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) { |
|
276 | - $list->add($set); |
|
277 | - } else { |
|
278 | - if (count($ancestors)) { |
|
279 | - foreach ($ancestors as $ancestor) { |
|
280 | - if (in_array($ancestor, $restrictedToParerentIDs)) { |
|
281 | - $list->add($set); |
|
282 | - continue; |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - } else { |
|
288 | - $list->add($set); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - return $list; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Get all Blocks from BlockSets that apply to this page. |
|
297 | - * |
|
298 | - * @return ArrayList |
|
299 | - * */ |
|
300 | - public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false) |
|
301 | - { |
|
302 | - $blocks = ArrayList::create(); |
|
303 | - $sets = $this->getAppliedSets(); |
|
304 | - |
|
305 | - if (!$sets->count()) { |
|
306 | - return $blocks; |
|
307 | - } |
|
308 | - |
|
309 | - foreach ($sets as $set) { |
|
310 | - $setBlocks = $set->Blocks()->sort('Sort DESC'); |
|
311 | - |
|
312 | - if (!$includeDisabled) { |
|
313 | - $setBlocks = $setBlocks->exclude('ID', $this->owner->DisabledBlocks()->column('ID')); |
|
314 | - } |
|
315 | - |
|
316 | - if ($area) { |
|
317 | - $setBlocks = $setBlocks->filter('BlockArea', $area); |
|
318 | - } |
|
319 | - |
|
320 | - $blocks->merge($setBlocks); |
|
321 | - } |
|
322 | - |
|
323 | - $blocks->removeDuplicates(); |
|
324 | - |
|
325 | - return $blocks; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Get's the link for a block area preview button. |
|
330 | - * |
|
331 | - * @return string |
|
332 | - * */ |
|
333 | - public function areasPreviewLink() |
|
334 | - { |
|
335 | - return Controller::join_links($this->owner->Link(), '?block_preview=1'); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get's html for a block area preview button. |
|
340 | - * |
|
341 | - * @return string |
|
342 | - * */ |
|
343 | - public function areasPreviewButton() |
|
344 | - { |
|
345 | - return "<a class='btn btn-primary' style='font-style:normal;' href='".$this->areasPreviewLink()."' target='_blank'>"._t('BlocksSiteTreeExtension.PreviewBlockAreasLink', 'Preview Block Areas for this page').'</a>'; |
|
346 | - } |
|
30 | + private static $db = [ |
|
31 | + 'InheritBlockSets' => 'Boolean', |
|
32 | + ]; |
|
33 | + |
|
34 | + private static $many_many = [ |
|
35 | + "Blocks" => Block::class, |
|
36 | + "DisabledBlocks" => Block::class, |
|
37 | + ]; |
|
38 | + |
|
39 | + public static $many_many_extraFields = [ |
|
40 | + 'Blocks' => [ |
|
41 | + 'Sort' => 'Int', |
|
42 | + 'BlockArea' => 'Varchar', |
|
43 | + ], |
|
44 | + ]; |
|
45 | + |
|
46 | + private static $defaults = [ |
|
47 | + 'InheritBlockSets' => 1, |
|
48 | + ]; |
|
49 | + |
|
50 | + private static $dependencies = [ |
|
51 | + 'blockManager' => '%$blockManager', |
|
52 | + ]; |
|
53 | + |
|
54 | + public $blockManager; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Check if the Blocks CMSFields should be displayed for this Page |
|
59 | + * |
|
60 | + * @return boolean |
|
61 | + **/ |
|
62 | + public function showBlocksFields() |
|
63 | + { |
|
64 | + $whiteList = $this->blockManager->getWhiteListedPageTypes(); |
|
65 | + $blackList = $this->blockManager->getBlackListedPageTypes(); |
|
66 | + |
|
67 | + if (in_array($this->owner->ClassName, $blackList)) { |
|
68 | + return false; |
|
69 | + } |
|
70 | + |
|
71 | + if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) { |
|
72 | + return false; |
|
73 | + } |
|
74 | + |
|
75 | + if (!Permission::check('BLOCK_EDIT')) { |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + return true; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Block manager for Pages. |
|
84 | + * */ |
|
85 | + public function updateCMSFields(FieldList $fields) |
|
86 | + { |
|
87 | + if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) { |
|
88 | + return; |
|
89 | + } |
|
90 | + |
|
91 | + $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); |
|
92 | + |
|
93 | + if ($areas && count($areas)) { |
|
94 | + $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks'))); |
|
95 | + if (BlockManager::config()->get('block_area_preview')) { |
|
96 | + $fields->addFieldToTab('Root.Blocks', |
|
97 | + LiteralField::create('PreviewLink', $this->areasPreviewButton())); |
|
98 | + } |
|
99 | + |
|
100 | + // Blocks related directly to this Page |
|
101 | + $gridConfig = GridFieldConfigBlockManager::create(true, true, true, true) |
|
102 | + ->addExisting($this->owner->class) |
|
103 | + //->addBulkEditing() |
|
104 | + // ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete. |
|
105 | + ; |
|
106 | + |
|
107 | + |
|
108 | + // TODO it seems this sort is not being applied... |
|
109 | + $gridSource = $this->owner->Blocks(); |
|
110 | + // ->sort(array( |
|
111 | + // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', |
|
112 | + // 'SiteTree_Blocks.Sort' => 'ASC', |
|
113 | + // 'Name' => 'ASC' |
|
114 | + // )); |
|
115 | + |
|
116 | + $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); |
|
117 | + |
|
118 | + |
|
119 | + // Blocks inherited from BlockSets |
|
120 | + if ($this->blockManager->getUseBlockSets()) { |
|
121 | + $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); |
|
122 | + |
|
123 | + if ($inheritedBlocks->count()) { |
|
124 | + $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); |
|
125 | + |
|
126 | + if ($activeInherited->count()) { |
|
127 | + $fields->addFieldsToTab('Root.Blocks', [ |
|
128 | + GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, |
|
129 | + GridFieldConfigBlockManager::create(false, false, false)), |
|
130 | + LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'), |
|
131 | + ]); |
|
132 | + } |
|
133 | + |
|
134 | + $fields->addFieldToTab('Root.Blocks', |
|
135 | + ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), |
|
136 | + $inheritedBlocks->map('ID', 'Title'), null, null, true) |
|
137 | + ->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')) |
|
138 | + ); |
|
139 | + } else { |
|
140 | + $fields->addFieldToTab('Root.Blocks', |
|
141 | + ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), |
|
142 | + _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.'))); |
|
143 | + } |
|
144 | + |
|
145 | + $fields->addFieldToTab('Root.Blocks', |
|
146 | + CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets'))); |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Called from templates to get rendered blocks for the given area. |
|
153 | + * |
|
154 | + * @param string $area |
|
155 | + * @param int $limit Limit the items to this number, or null for no limit |
|
156 | + */ |
|
157 | + public function BlockArea($area, $limit = null) |
|
158 | + { |
|
159 | + if ($this->owner->ID <= 0) { |
|
160 | + return; |
|
161 | + } // blocks break on fake pages ie Security/login |
|
162 | + |
|
163 | + $list = $this->getBlockList($area); |
|
164 | + |
|
165 | + foreach ($list as $block) { |
|
166 | + if (!$block->canView()) { |
|
167 | + $list->remove($block); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + if ($limit !== null) { |
|
172 | + $list = $list->limit($limit); |
|
173 | + } |
|
174 | + |
|
175 | + $data = []; |
|
176 | + $data['HasBlockArea'] = ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) || $list->Count() > 0; |
|
177 | + $data['BlockArea'] = $list; |
|
178 | + $data['AreaID'] = $area; |
|
179 | + |
|
180 | + $data = $this->owner->customise($data); |
|
181 | + |
|
182 | + $template = ['BlockArea_'.$area]; |
|
183 | + |
|
184 | + if (SSViewer::hasTemplate($template)) { |
|
185 | + return $data->renderWith($template); |
|
186 | + } else { |
|
187 | + return $data->renderWith('BlockArea'); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + public function HasBlockArea($area) |
|
192 | + { |
|
193 | + if ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) { |
|
194 | + return true; |
|
195 | + } |
|
196 | + |
|
197 | + $list = $this->getBlockList($area); |
|
198 | + |
|
199 | + foreach ($list as $block) { |
|
200 | + if (!$block->canView()) { |
|
201 | + $list->remove($block); |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + return $list->Count() > 0; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get a merged list of all blocks on this page and ones inherited from BlockSets. |
|
210 | + * |
|
211 | + * @param string|null $area filter by block area |
|
212 | + * @param bool $includeDisabled Include blocks that have been explicitly excluded from this page |
|
213 | + * i.e. blocks from block sets added to the "disable inherited blocks" list |
|
214 | + * |
|
215 | + * @return ArrayList |
|
216 | + * */ |
|
217 | + public function getBlockList($area = null, $includeDisabled = false) |
|
218 | + { |
|
219 | + $includeSets = $this->blockManager->getUseBlockSets() && $this->owner->InheritBlockSets; |
|
220 | + $blocks = ArrayList::create(); |
|
221 | + |
|
222 | + // get blocks directly linked to this page |
|
223 | + $nativeBlocks = $this->owner->Blocks()->sort('Sort'); |
|
224 | + if ($area) { |
|
225 | + $nativeBlocks = $nativeBlocks->filter('BlockArea', $area); |
|
226 | + } |
|
227 | + |
|
228 | + if ($nativeBlocks->count()) { |
|
229 | + foreach ($nativeBlocks as $block) { |
|
230 | + $blocks->add($block); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + // get blocks from BlockSets |
|
235 | + if ($includeSets) { |
|
236 | + $blocksFromSets = $this->getBlocksFromAppliedBlockSets($area, $includeDisabled); |
|
237 | + if ($blocksFromSets->count()) { |
|
238 | + // merge set sources |
|
239 | + foreach ($blocksFromSets as $block) { |
|
240 | + if (!$blocks->find('ID', $block->ID)) { |
|
241 | + if ($block->AboveOrBelow == 'Above') { |
|
242 | + $blocks->unshift($block); |
|
243 | + } else { |
|
244 | + $blocks->push($block); |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + return $blocks; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Get Any BlockSets that apply to this page. |
|
256 | + * |
|
257 | + * @return ArrayList |
|
258 | + * */ |
|
259 | + public function getAppliedSets() |
|
260 | + { |
|
261 | + $list = ArrayList::create(); |
|
262 | + if (!$this->owner->InheritBlockSets) { |
|
263 | + return $list; |
|
264 | + } |
|
265 | + |
|
266 | + $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')"); |
|
267 | + $ancestors = $this->owner->getAncestors()->column('ID'); |
|
268 | + |
|
269 | + foreach ($sets as $set) { |
|
270 | + $restrictedToParerentIDs = $set->PageParents()->column('ID'); |
|
271 | + if (count($restrictedToParerentIDs)) { |
|
272 | + // check whether the set should include selected parent, in which case check whether |
|
273 | + // it was in the restricted parents list. If it's not, or if include parentpage |
|
274 | + // wasn't selected, we check the ancestors of this page. |
|
275 | + if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) { |
|
276 | + $list->add($set); |
|
277 | + } else { |
|
278 | + if (count($ancestors)) { |
|
279 | + foreach ($ancestors as $ancestor) { |
|
280 | + if (in_array($ancestor, $restrictedToParerentIDs)) { |
|
281 | + $list->add($set); |
|
282 | + continue; |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + } else { |
|
288 | + $list->add($set); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + return $list; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Get all Blocks from BlockSets that apply to this page. |
|
297 | + * |
|
298 | + * @return ArrayList |
|
299 | + * */ |
|
300 | + public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false) |
|
301 | + { |
|
302 | + $blocks = ArrayList::create(); |
|
303 | + $sets = $this->getAppliedSets(); |
|
304 | + |
|
305 | + if (!$sets->count()) { |
|
306 | + return $blocks; |
|
307 | + } |
|
308 | + |
|
309 | + foreach ($sets as $set) { |
|
310 | + $setBlocks = $set->Blocks()->sort('Sort DESC'); |
|
311 | + |
|
312 | + if (!$includeDisabled) { |
|
313 | + $setBlocks = $setBlocks->exclude('ID', $this->owner->DisabledBlocks()->column('ID')); |
|
314 | + } |
|
315 | + |
|
316 | + if ($area) { |
|
317 | + $setBlocks = $setBlocks->filter('BlockArea', $area); |
|
318 | + } |
|
319 | + |
|
320 | + $blocks->merge($setBlocks); |
|
321 | + } |
|
322 | + |
|
323 | + $blocks->removeDuplicates(); |
|
324 | + |
|
325 | + return $blocks; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Get's the link for a block area preview button. |
|
330 | + * |
|
331 | + * @return string |
|
332 | + * */ |
|
333 | + public function areasPreviewLink() |
|
334 | + { |
|
335 | + return Controller::join_links($this->owner->Link(), '?block_preview=1'); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get's html for a block area preview button. |
|
340 | + * |
|
341 | + * @return string |
|
342 | + * */ |
|
343 | + public function areasPreviewButton() |
|
344 | + { |
|
345 | + return "<a class='btn btn-primary' style='font-style:normal;' href='".$this->areasPreviewLink()."' target='_blank'>"._t('BlocksSiteTreeExtension.PreviewBlockAreasLink', 'Preview Block Areas for this page').'</a>'; |
|
346 | + } |
|
347 | 347 | } |
@@ -139,7 +139,7 @@ |
||
139 | 139 | } else { |
140 | 140 | $fields->addFieldToTab('Root.Blocks', |
141 | 141 | ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), |
142 | - _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.'))); |
|
142 | + _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable', 'This page has no inherited blocks to disable.'))); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | $fields->addFieldToTab('Root.Blocks', |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | protected $controller; |
127 | 127 | |
128 | 128 | /** |
129 | - * @return mixed |
|
129 | + * @return string |
|
130 | 130 | */ |
131 | 131 | public function getTypeForGridfield() |
132 | 132 | { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * looks for templates that match BlockClassName_AreaName |
238 | 238 | * falls back to BlockClassName. |
239 | 239 | * |
240 | - * @return string |
|
240 | + * @return DBHTMLText |
|
241 | 241 | **/ |
242 | 242 | public function forTemplate() |
243 | 243 | { |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * @return string |
|
256 | + * @return DBHTMLText |
|
257 | 257 | */ |
258 | 258 | public function BlockHTML() |
259 | 259 | { |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | /** |
429 | 429 | * Check if this block has been published. |
430 | 430 | * |
431 | - * @return bool True if this page has been published. |
|
431 | + * @return string True if this page has been published. |
|
432 | 432 | */ |
433 | 433 | public function isPublishedNice() |
434 | 434 | { |
@@ -34,7 +34,7 @@ |
||
34 | 34 | class Block extends DataObject implements PermissionProvider |
35 | 35 | { |
36 | 36 | |
37 | - private static $table_name = 'Block'; |
|
37 | + private static $table_name = 'Block'; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @var array |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function fieldLabels($includerelations = true) |
76 | 76 | { |
77 | - $labels = parent::fieldLabels($includerelations); |
|
77 | + $labels = parent::fieldLabels($includerelations); |
|
78 | 78 | |
79 | 79 | $labels = array_merge($labels, [ |
80 | 80 | 'singular_name' => _t('Block.BlockType', 'Block Type'), |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $self = $this; |
139 | 139 | $this->beforeUpdateCMSFields(function($fields) use($self) { |
140 | 140 | /** @var FieldList $fields */ |
141 | - Requirements::add_i18n_javascript(BLOCKS_DIR . '/javascript/lang'); |
|
141 | + Requirements::add_i18n_javascript(BLOCKS_DIR.'/javascript/lang'); |
|
142 | 142 | |
143 | 143 | // this line is a temporary patch until I can work out why this dependency isn't being |
144 | 144 | // loaded in some cases... |
@@ -445,9 +445,9 @@ discard block |
||
445 | 445 | { |
446 | 446 | $obj = DBHTMLText::create(); |
447 | 447 | if ($this->isPublished()) { |
448 | - $obj->setValue('<img src="' . FRAMEWORK_ADMIN_DIR . '/images/alert-good.gif" />'); |
|
448 | + $obj->setValue('<img src="'.FRAMEWORK_ADMIN_DIR.'/images/alert-good.gif" />'); |
|
449 | 449 | } else { |
450 | - $obj->setValue('<img src="' . FRAMEWORK_ADMIN_DIR . '/images/alert-bad.gif" />'); |
|
450 | + $obj->setValue('<img src="'.FRAMEWORK_ADMIN_DIR.'/images/alert-bad.gif" />'); |
|
451 | 451 | } |
452 | 452 | return $obj; |
453 | 453 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | /** |
127 | 127 | * Returns a list of pages this BlockSet features on. |
128 | 128 | * |
129 | - * @return DataList |
|
129 | + * @return \SilverStripe\ORM\DataList |
|
130 | 130 | */ |
131 | 131 | public function Pages() |
132 | 132 | { |
@@ -2,13 +2,11 @@ |
||
2 | 2 | |
3 | 3 | namespace SheaDawson\Blocks\Model; |
4 | 4 | |
5 | -use SheaDawson\Blocks\Forms\GridFieldConfigBlockManager; |
|
6 | 5 | use SilverStripe\ORM\DataObject; |
7 | 6 | use SilverStripe\ORM\ArrayLib; |
8 | 7 | use SilverStripe\CMS\Model\SiteTree; |
9 | 8 | use SilverStripe\Security\PermissionProvider; |
10 | 9 | use SilverStripe\Security\Permission; |
11 | -use SilverStripe\Security\Group; |
|
12 | 10 | use SilverStripe\Forms\TreeMultiselectField; |
13 | 11 | use SilverStripe\Forms\CheckboxField; |
14 | 12 | use SilverStripe\Forms\HeaderField; |
@@ -89,8 +89,8 @@ |
||
89 | 89 | $fields->removeFieldFromTab('Root', 'Blocks'); |
90 | 90 | |
91 | 91 | /** |
92 | - * @todo - change relation editor back to the custom block manager config and fix issues when 'creating' Blocks from a BlockSet. |
|
93 | - */ |
|
92 | + * @todo - change relation editor back to the custom block manager config and fix issues when 'creating' Blocks from a BlockSet. |
|
93 | + */ |
|
94 | 94 | $gridConfig = GridFieldConfig_RelationEditor::create(); |
95 | 95 | $gridConfig->addComponent(new GridFieldOrderableRows('Sort')); |
96 | 96 | $gridConfig->addComponent(new GridFieldDeleteAction()); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', _t('BlockSet.OnlyApplyToThesePageTypes', 'Only apply to these Page Types:'), $this->pageTypeOptions()) |
79 | 79 | ->setDescription(_t('BlockSet.OnlyApplyToThesePageTypesDescription', 'Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.'))); |
80 | 80 | $fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', _t('BlockSet.OnlyApplyToChildrenOfThesePages', 'Only apply to children of these Pages:'), 'SilverStripe\\CMS\\Model\\SiteTree')); |
81 | - $fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren','Apply block set to selected page parents as well as children'))); |
|
81 | + $fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren', 'Apply block set to selected page parents as well as children'))); |
|
82 | 82 | |
83 | 83 | if (!$this->ID) { |
84 | 84 | $fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>"._t('BlockSet.YouCanAddBlocksToThisSetOnceYouHaveSavedIt', 'You can add Blocks to this set once you have saved it for the first time').'</p>')); |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | { |
169 | 169 | return [ |
170 | 170 | 'BLOCKSET_EDIT' => [ |
171 | - 'name' => _t('BlockSet.EditBlockSet','Edit a Block Set'), |
|
171 | + 'name' => _t('BlockSet.EditBlockSet', 'Edit a Block Set'), |
|
172 | 172 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
173 | 173 | ], |
174 | 174 | 'BLOCKSET_DELETE' => [ |
175 | - 'name' => _t('BlockSet.DeleteBlockSet','Delete a Block Set'), |
|
175 | + 'name' => _t('BlockSet.DeleteBlockSet', 'Delete a Block Set'), |
|
176 | 176 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
177 | 177 | ], |
178 | 178 | 'BLOCKSET_CREATE' => [ |
179 | - 'name' => _t('BlockSet.CreateBlockSet','Create a Block Set'), |
|
179 | + 'name' => _t('BlockSet.CreateBlockSet', 'Create a Block Set'), |
|
180 | 180 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
181 | 181 | ], |
182 | 182 | ]; |
@@ -80,15 +80,15 @@ |
||
80 | 80 | $object = singleton(BlockSet::class); |
81 | 81 | $expected = [ |
82 | 82 | 'BLOCKSET_EDIT' => [ |
83 | - 'name' => _t('BlockSet.EditBlockSet','Edit a Block Set'), |
|
83 | + 'name' => _t('BlockSet.EditBlockSet', 'Edit a Block Set'), |
|
84 | 84 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
85 | 85 | ], |
86 | 86 | 'BLOCKSET_DELETE' => [ |
87 | - 'name' => _t('BlockSet.DeleteBlockSet','Delete a Block Set'), |
|
87 | + 'name' => _t('BlockSet.DeleteBlockSet', 'Delete a Block Set'), |
|
88 | 88 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
89 | 89 | ], |
90 | 90 | 'BLOCKSET_CREATE' => [ |
91 | - 'name' => _t('BlockSet.CreateBlockSet','Create a Block Set'), |
|
91 | + 'name' => _t('BlockSet.CreateBlockSet', 'Create a Block Set'), |
|
92 | 92 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
93 | 93 | ], |
94 | 94 | ]; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | class ContentBlock extends Block |
6 | 6 | { |
7 | - private static $table_name = "ContentBlock"; |
|
7 | + private static $table_name = "ContentBlock"; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * If the singular name is set in a private static $singular_name, it cannot be changed using the translation files |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | 'Content' => 'HTMLText', |
31 | 31 | ]; |
32 | 32 | |
33 | - public function fieldLabels($includeRelations = true) |
|
34 | - { |
|
35 | - return array_merge( |
|
36 | - parent::fieldLabels($includeRelations), |
|
37 | - [ |
|
38 | - 'Content' => _t('Block.Content', 'Content'), |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
33 | + public function fieldLabels($includeRelations = true) |
|
34 | + { |
|
35 | + return array_merge( |
|
36 | + parent::fieldLabels($includeRelations), |
|
37 | + [ |
|
38 | + 'Content' => _t('Block.Content', 'Content'), |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'Silverstripe\\Forms\\ReadonlyField'), |
54 | 54 | 'BlockArea' => array( |
55 | 55 | 'title' => _t('Block.BlockArea', 'Block Area'), |
56 | - 'callback' => function () use ($areasFieldSource) { |
|
56 | + 'callback' => function() use ($areasFieldSource) { |
|
57 | 57 | $areasField = DropdownField::create('BlockArea', 'Block Area', $areasFieldSource); |
58 | 58 | if (count($areasFieldSource) > 1) { |
59 | 59 | $areasField->setHasEmptyDefault(true); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | if ($aboveOrBelow) { |
69 | 69 | $displayfields['AboveOrBelow'] = array( |
70 | 70 | 'title' => _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), |
71 | - 'callback' => function () { |
|
71 | + 'callback' => function() { |
|
72 | 72 | return DropdownField::create('AboveOrBelow', _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), BlockSet::config()->get('above_or_below_options')); |
73 | 73 | }, |
74 | 74 | ); |
@@ -13,15 +13,15 @@ |
||
13 | 13 | */ |
14 | 14 | class BlockSiteConfigExtension extends DataExtension |
15 | 15 | { |
16 | - private static $many_many = [ |
|
17 | - "Blocks" => Block::class, |
|
18 | - ]; |
|
16 | + private static $many_many = [ |
|
17 | + "Blocks" => Block::class, |
|
18 | + ]; |
|
19 | 19 | |
20 | - /** |
|
21 | - * |
|
22 | - **/ |
|
23 | - public function updateCMSFields(FieldList $fields) |
|
24 | - { |
|
25 | - $fields->removeByName('Blocks'); |
|
26 | - } |
|
20 | + /** |
|
21 | + * |
|
22 | + **/ |
|
23 | + public function updateCMSFields(FieldList $fields) |
|
24 | + { |
|
25 | + $fields->removeByName('Blocks'); |
|
26 | + } |
|
27 | 27 | } |