@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * Can a user view this SiteConfig instance? |
278 | 278 | * |
279 | 279 | * @param Member $member |
280 | - * @return boolean |
|
280 | + * @return boolean|string |
|
281 | 281 | */ |
282 | 282 | public function canView($member = null) |
283 | 283 | { |
@@ -372,6 +372,9 @@ discard block |
||
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
375 | + /** |
|
376 | + * @param Member $member |
|
377 | + */ |
|
375 | 378 | public function canEdit($member = null) |
376 | 379 | { |
377 | 380 | if (!$member) { |
@@ -35,418 +35,418 @@ |
||
35 | 35 | */ |
36 | 36 | class SiteConfig extends DataObject implements PermissionProvider, TemplateGlobalProvider |
37 | 37 | { |
38 | - private static $db = array( |
|
39 | - "Title" => "Varchar(255)", |
|
40 | - "Tagline" => "Varchar(255)", |
|
41 | - "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')", |
|
42 | - "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
43 | - "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
44 | - ); |
|
45 | - |
|
46 | - private static $many_many = array( |
|
47 | - "ViewerGroups" => "SilverStripe\\Security\\Group", |
|
48 | - "EditorGroups" => "SilverStripe\\Security\\Group", |
|
49 | - "CreateTopLevelGroups" => "SilverStripe\\Security\\Group" |
|
50 | - ); |
|
51 | - |
|
52 | - private static $defaults = array( |
|
53 | - "CanViewType" => "Anyone", |
|
54 | - "CanEditType" => "LoggedInUsers", |
|
55 | - "CanCreateTopLevelType" => "LoggedInUsers", |
|
56 | - ); |
|
57 | - |
|
58 | - private static $table_name = 'SiteConfig'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Default permission to check for 'LoggedInUsers' to create or edit pages |
|
62 | - * |
|
63 | - * @var array |
|
64 | - * @config |
|
65 | - */ |
|
66 | - private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'); |
|
67 | - |
|
68 | - |
|
69 | - public function populateDefaults() |
|
70 | - { |
|
71 | - $this->Title = _t('SilverStripe\\SiteConfig\\SiteConfig.SITENAMEDEFAULT', "Your Site Name"); |
|
72 | - $this->Tagline = _t('SilverStripe\\SiteConfig\\SiteConfig.TAGLINEDEFAULT', "your tagline here"); |
|
73 | - |
|
74 | - // Allow these defaults to be overridden |
|
75 | - parent::populateDefaults(); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Get the fields that are sent to the CMS. |
|
80 | - * |
|
81 | - * In your extensions: updateCMSFields($fields). |
|
82 | - * |
|
83 | - * @return FieldList |
|
84 | - */ |
|
85 | - public function getCMSFields() |
|
86 | - { |
|
87 | - $mapFn = function ($groups = []) { |
|
88 | - $map = []; |
|
89 | - foreach ($groups as $group) { |
|
90 | - // Listboxfield values are escaped, use ASCII char instead of » |
|
91 | - $map[$group->ID] = $group->getBreadcrumbs(' > '); |
|
92 | - } |
|
93 | - asort($map); |
|
94 | - return $map; |
|
95 | - }; |
|
96 | - $groupsMap = $mapFn(Group::get()); |
|
97 | - $viewAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_VIEW_ALL', 'ADMIN'])); |
|
98 | - $editAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_EDIT_ALL', 'ADMIN'])); |
|
99 | - |
|
100 | - $fields = new FieldList( |
|
101 | - new TabSet( |
|
102 | - "Root", |
|
103 | - $tabMain = new Tab( |
|
104 | - 'Main', |
|
105 | - $titleField = new TextField("Title", _t('SilverStripe\\SiteConfig\\SiteConfig.SITETITLE', "Site title")), |
|
106 | - $taglineField = new TextField("Tagline", _t('SilverStripe\\SiteConfig\\SiteConfig.SITETAGLINE', "Site Tagline/Slogan")) |
|
107 | - ), |
|
108 | - $tabAccess = new Tab( |
|
109 | - 'Access', |
|
110 | - $viewersOptionsField = new OptionsetField("CanViewType", _t('SilverStripe\\SiteConfig\\SiteConfig.VIEWHEADER', "Who can view pages on this site?")), |
|
111 | - $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SilverStripe\\CMS\\Model\\SiteTree.VIEWERGROUPS', "Viewer Groups")) |
|
112 | - ->setSource($groupsMap) |
|
113 | - ->setAttribute( |
|
114 | - 'data-placeholder', |
|
115 | - _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
116 | - ), |
|
117 | - $editorsOptionsField = new OptionsetField("CanEditType", _t('SilverStripe\\SiteConfig\\SiteConfig.EDITHEADER', "Who can edit pages on this site?")), |
|
118 | - $editorGroupsField = ListboxField::create("EditorGroups", _t('SilverStripe\\CMS\\Model\\SiteTree.EDITORGROUPS', "Editor Groups")) |
|
119 | - ->setSource($groupsMap) |
|
120 | - ->setAttribute( |
|
121 | - 'data-placeholder', |
|
122 | - _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
123 | - ), |
|
124 | - $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SilverStripe\\SiteConfig\\SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")), |
|
125 | - $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t(__CLASS__.'.TOPLEVELCREATORGROUPS', "Top level creators")) |
|
126 | - ->setSource($groupsMap) |
|
127 | - ->setAttribute( |
|
128 | - 'data-placeholder', |
|
129 | - _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
130 | - ) |
|
131 | - ) |
|
132 | - ), |
|
133 | - new HiddenField('ID') |
|
134 | - ); |
|
135 | - |
|
136 | - $viewersOptionsSource = array(); |
|
137 | - $viewersOptionsSource["Anyone"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSANYONE', "Anyone"); |
|
138 | - $viewersOptionsSource["LoggedInUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSLOGGEDIN', "Logged-in users"); |
|
139 | - $viewersOptionsSource["OnlyTheseUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)"); |
|
140 | - $viewersOptionsField->setSource($viewersOptionsSource); |
|
141 | - |
|
142 | - if ($viewAllGroupsMap) { |
|
143 | - $viewerGroupsField->setDescription(_t( |
|
144 | - 'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC', |
|
145 | - 'Groups with global view permissions: {groupList}', |
|
146 | - ['groupList' => implode(', ', array_values($viewAllGroupsMap))] |
|
147 | - )); |
|
148 | - } |
|
149 | - |
|
150 | - if ($editAllGroupsMap) { |
|
151 | - $editorGroupsField->setDescription(_t( |
|
152 | - 'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC', |
|
153 | - 'Groups with global edit permissions: {groupList}', |
|
154 | - ['groupList' => implode(', ', array_values($editAllGroupsMap))] |
|
155 | - )); |
|
156 | - } |
|
157 | - |
|
158 | - $editorsOptionsSource = array(); |
|
159 | - $editorsOptionsSource["LoggedInUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); |
|
160 | - $editorsOptionsSource["OnlyTheseUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.EDITONLYTHESE', "Only these groups (choose from list)"); |
|
161 | - $editorsOptionsField->setSource($editorsOptionsSource); |
|
162 | - |
|
163 | - $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); |
|
164 | - |
|
165 | - if (!Permission::check('EDIT_SITECONFIG')) { |
|
166 | - $fields->makeFieldReadonly($viewersOptionsField); |
|
167 | - $fields->makeFieldReadonly($viewerGroupsField); |
|
168 | - $fields->makeFieldReadonly($editorsOptionsField); |
|
169 | - $fields->makeFieldReadonly($editorGroupsField); |
|
170 | - $fields->makeFieldReadonly($topLevelCreatorsOptionsField); |
|
171 | - $fields->makeFieldReadonly($topLevelCreatorsGroupsField); |
|
172 | - $fields->makeFieldReadonly($taglineField); |
|
173 | - $fields->makeFieldReadonly($titleField); |
|
174 | - } |
|
175 | - |
|
176 | - if (file_exists(BASE_PATH . '/install.php')) { |
|
177 | - $fields->addFieldToTab( |
|
178 | - "Root.Main", |
|
179 | - new LiteralField( |
|
180 | - "InstallWarningHeader", |
|
181 | - "<p class=\"message warning\">" . _t( |
|
182 | - "SilverStripe\\CMS\\Model\\SiteTree.REMOVE_INSTALL_WARNING", |
|
183 | - "Warning: You should remove install.php from this SilverStripe install for security reasons." |
|
184 | - ) . "</p>" |
|
185 | - ), |
|
186 | - "Title" |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - $tabMain->setTitle(_t('SilverStripe\\SiteConfig\\SiteConfig.TABMAIN', "Main")); |
|
191 | - $tabAccess->setTitle(_t('SilverStripe\\SiteConfig\\SiteConfig.TABACCESS', "Access")); |
|
192 | - $this->extend('updateCMSFields', $fields); |
|
193 | - |
|
194 | - return $fields; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get the actions that are sent to the CMS. |
|
199 | - * |
|
200 | - * In your extensions: updateEditFormActions($actions) |
|
201 | - * |
|
202 | - * @return FieldList |
|
203 | - */ |
|
204 | - public function getCMSActions() |
|
205 | - { |
|
206 | - if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) { |
|
207 | - $actions = new FieldList( |
|
208 | - FormAction::create( |
|
209 | - 'save_siteconfig', |
|
210 | - _t('SilverStripe\\CMS\\Controllers\\CMSMain.SAVE', 'Save') |
|
211 | - )->addExtraClass('btn-primary font-icon-save') |
|
212 | - ); |
|
213 | - } else { |
|
214 | - $actions = new FieldList(); |
|
215 | - } |
|
216 | - |
|
217 | - $this->extend('updateCMSActions', $actions); |
|
218 | - |
|
219 | - return $actions; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function CMSEditLink() |
|
226 | - { |
|
227 | - return SiteConfigLeftAndMain::singleton()->Link(); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Get the current sites SiteConfig, and creates a new one through |
|
232 | - * {@link make_site_config()} if none is found. |
|
233 | - * |
|
234 | - * @return SiteConfig |
|
235 | - */ |
|
236 | - public static function current_site_config() |
|
237 | - { |
|
238 | - /** @var SiteConfig $siteConfig */ |
|
239 | - $siteConfig = DataObject::get_one(SiteConfig::class); |
|
240 | - if ($siteConfig) { |
|
241 | - return $siteConfig; |
|
242 | - } |
|
243 | - |
|
244 | - return self::make_site_config(); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Setup a default SiteConfig record if none exists. |
|
249 | - */ |
|
250 | - public function requireDefaultRecords() |
|
251 | - { |
|
252 | - parent::requireDefaultRecords(); |
|
253 | - |
|
254 | - $config = DataObject::get_one(SiteConfig::class); |
|
255 | - |
|
256 | - if (!$config) { |
|
257 | - self::make_site_config(); |
|
258 | - |
|
259 | - DB::alteration_message("Added default site config", "created"); |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Create SiteConfig with defaults from language file. |
|
265 | - * |
|
266 | - * @return SiteConfig |
|
267 | - */ |
|
268 | - public static function make_site_config() |
|
269 | - { |
|
270 | - $config = SiteConfig::create(); |
|
271 | - $config->write(); |
|
272 | - |
|
273 | - return $config; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Can a user view this SiteConfig instance? |
|
278 | - * |
|
279 | - * @param Member $member |
|
280 | - * @return boolean |
|
281 | - */ |
|
282 | - public function canView($member = null) |
|
283 | - { |
|
284 | - if (!$member) { |
|
285 | - $member = Security::getCurrentUser(); |
|
286 | - } |
|
287 | - |
|
288 | - $extended = $this->extendedCan('canView', $member); |
|
289 | - if ($extended !== null) { |
|
290 | - return $extended; |
|
291 | - } |
|
292 | - |
|
293 | - // Assuming all that can edit this object can also view it |
|
294 | - return $this->canEdit($member); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Can a user view pages on this site? This method is only |
|
299 | - * called if a page is set to Inherit, but there is nothing |
|
300 | - * to inherit from. |
|
301 | - * |
|
302 | - * @param Member $member |
|
303 | - * @return boolean |
|
304 | - */ |
|
305 | - public function canViewPages($member = null) |
|
306 | - { |
|
307 | - if (!$member) { |
|
308 | - $member = Security::getCurrentUser(); |
|
309 | - } |
|
310 | - |
|
311 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
312 | - return true; |
|
313 | - } |
|
314 | - |
|
315 | - $extended = $this->extendedCan('canViewPages', $member); |
|
316 | - if ($extended !== null) { |
|
317 | - return $extended; |
|
318 | - } |
|
319 | - |
|
320 | - if (!$this->CanViewType || $this->CanViewType == 'Anyone') { |
|
321 | - return true; |
|
322 | - } |
|
323 | - |
|
324 | - // check for any logged-in users |
|
325 | - if ($this->CanViewType === 'LoggedInUsers' && $member) { |
|
326 | - return true; |
|
327 | - } |
|
328 | - |
|
329 | - // check for specific groups |
|
330 | - if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) { |
|
331 | - return true; |
|
332 | - } |
|
333 | - |
|
334 | - return false; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Can a user edit pages on this site? This method is only |
|
339 | - * called if a page is set to Inherit, but there is nothing |
|
340 | - * to inherit from, or on new records without a parent. |
|
341 | - * |
|
342 | - * @param Member $member |
|
343 | - * @return boolean |
|
344 | - */ |
|
345 | - public function canEditPages($member = null) |
|
346 | - { |
|
347 | - if (!$member) { |
|
348 | - $member = Security::getCurrentUser(); |
|
349 | - } |
|
350 | - |
|
351 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
352 | - return true; |
|
353 | - } |
|
354 | - |
|
355 | - $extended = $this->extendedCan('canEditPages', $member); |
|
356 | - if ($extended !== null) { |
|
357 | - return $extended; |
|
358 | - } |
|
359 | - |
|
360 | - // check for any logged-in users with CMS access |
|
361 | - if ($this->CanEditType === 'LoggedInUsers' |
|
362 | - && Permission::checkMember($member, $this->config()->get('required_permission')) |
|
363 | - ) { |
|
364 | - return true; |
|
365 | - } |
|
366 | - |
|
367 | - // check for specific groups |
|
368 | - if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) { |
|
369 | - return true; |
|
370 | - } |
|
371 | - |
|
372 | - return false; |
|
373 | - } |
|
374 | - |
|
375 | - public function canEdit($member = null) |
|
376 | - { |
|
377 | - if (!$member) { |
|
378 | - $member = Security::getCurrentUser(); |
|
379 | - } |
|
380 | - |
|
381 | - $extended = $this->extendedCan('canEdit', $member); |
|
382 | - if ($extended !== null) { |
|
383 | - return $extended; |
|
384 | - } |
|
385 | - |
|
386 | - return Permission::checkMember($member, "EDIT_SITECONFIG"); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @return array |
|
391 | - */ |
|
392 | - public function providePermissions() |
|
393 | - { |
|
394 | - return array( |
|
395 | - 'EDIT_SITECONFIG' => array( |
|
396 | - 'name' => _t('SilverStripe\\SiteConfig\\SiteConfig.EDIT_PERMISSION', 'Manage site configuration'), |
|
397 | - 'category' => _t('SilverStripe\\Security\\Permission.PERMISSIONS_CATEGORY', 'Roles and access permissions'), |
|
398 | - 'help' => _t('SilverStripe\\SiteConfig\\SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'), |
|
399 | - 'sort' => 400 |
|
400 | - ) |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Can a user create pages in the root of this site? |
|
406 | - * |
|
407 | - * @param Member $member |
|
408 | - * @return boolean |
|
409 | - */ |
|
410 | - public function canCreateTopLevel($member = null) |
|
411 | - { |
|
412 | - if (!$member) { |
|
413 | - $member = Security::getCurrentUser(); |
|
414 | - } |
|
415 | - |
|
416 | - if ($member && Permission::checkMember($member, "ADMIN")) { |
|
417 | - return true; |
|
418 | - } |
|
419 | - |
|
420 | - $extended = $this->extendedCan('canCreateTopLevel', $member); |
|
421 | - if ($extended !== null) { |
|
422 | - return $extended; |
|
423 | - } |
|
424 | - |
|
425 | - // check for any logged-in users with CMS permission |
|
426 | - if ($this->CanCreateTopLevelType === 'LoggedInUsers' |
|
427 | - && Permission::checkMember($member, $this->config()->get('required_permission')) |
|
428 | - ) { |
|
429 | - return true; |
|
430 | - } |
|
431 | - |
|
432 | - // check for specific groups |
|
433 | - if ($this->CanCreateTopLevelType === 'OnlyTheseUsers' |
|
434 | - && $member |
|
435 | - && $member->inGroups($this->CreateTopLevelGroups()) |
|
436 | - ) { |
|
437 | - return true; |
|
438 | - } |
|
439 | - |
|
440 | - return false; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Add $SiteConfig to all SSViewers |
|
445 | - */ |
|
446 | - public static function get_template_global_variables() |
|
447 | - { |
|
448 | - return array( |
|
449 | - 'SiteConfig' => 'current_site_config', |
|
450 | - ); |
|
451 | - } |
|
38 | + private static $db = array( |
|
39 | + "Title" => "Varchar(255)", |
|
40 | + "Tagline" => "Varchar(255)", |
|
41 | + "CanViewType" => "Enum('Anyone, LoggedInUsers, OnlyTheseUsers', 'Anyone')", |
|
42 | + "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
43 | + "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", |
|
44 | + ); |
|
45 | + |
|
46 | + private static $many_many = array( |
|
47 | + "ViewerGroups" => "SilverStripe\\Security\\Group", |
|
48 | + "EditorGroups" => "SilverStripe\\Security\\Group", |
|
49 | + "CreateTopLevelGroups" => "SilverStripe\\Security\\Group" |
|
50 | + ); |
|
51 | + |
|
52 | + private static $defaults = array( |
|
53 | + "CanViewType" => "Anyone", |
|
54 | + "CanEditType" => "LoggedInUsers", |
|
55 | + "CanCreateTopLevelType" => "LoggedInUsers", |
|
56 | + ); |
|
57 | + |
|
58 | + private static $table_name = 'SiteConfig'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Default permission to check for 'LoggedInUsers' to create or edit pages |
|
62 | + * |
|
63 | + * @var array |
|
64 | + * @config |
|
65 | + */ |
|
66 | + private static $required_permission = array('CMS_ACCESS_CMSMain', 'CMS_ACCESS_LeftAndMain'); |
|
67 | + |
|
68 | + |
|
69 | + public function populateDefaults() |
|
70 | + { |
|
71 | + $this->Title = _t('SilverStripe\\SiteConfig\\SiteConfig.SITENAMEDEFAULT', "Your Site Name"); |
|
72 | + $this->Tagline = _t('SilverStripe\\SiteConfig\\SiteConfig.TAGLINEDEFAULT', "your tagline here"); |
|
73 | + |
|
74 | + // Allow these defaults to be overridden |
|
75 | + parent::populateDefaults(); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Get the fields that are sent to the CMS. |
|
80 | + * |
|
81 | + * In your extensions: updateCMSFields($fields). |
|
82 | + * |
|
83 | + * @return FieldList |
|
84 | + */ |
|
85 | + public function getCMSFields() |
|
86 | + { |
|
87 | + $mapFn = function ($groups = []) { |
|
88 | + $map = []; |
|
89 | + foreach ($groups as $group) { |
|
90 | + // Listboxfield values are escaped, use ASCII char instead of » |
|
91 | + $map[$group->ID] = $group->getBreadcrumbs(' > '); |
|
92 | + } |
|
93 | + asort($map); |
|
94 | + return $map; |
|
95 | + }; |
|
96 | + $groupsMap = $mapFn(Group::get()); |
|
97 | + $viewAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_VIEW_ALL', 'ADMIN'])); |
|
98 | + $editAllGroupsMap = $mapFn(Permission::get_groups_by_permission(['SITETREE_EDIT_ALL', 'ADMIN'])); |
|
99 | + |
|
100 | + $fields = new FieldList( |
|
101 | + new TabSet( |
|
102 | + "Root", |
|
103 | + $tabMain = new Tab( |
|
104 | + 'Main', |
|
105 | + $titleField = new TextField("Title", _t('SilverStripe\\SiteConfig\\SiteConfig.SITETITLE', "Site title")), |
|
106 | + $taglineField = new TextField("Tagline", _t('SilverStripe\\SiteConfig\\SiteConfig.SITETAGLINE', "Site Tagline/Slogan")) |
|
107 | + ), |
|
108 | + $tabAccess = new Tab( |
|
109 | + 'Access', |
|
110 | + $viewersOptionsField = new OptionsetField("CanViewType", _t('SilverStripe\\SiteConfig\\SiteConfig.VIEWHEADER', "Who can view pages on this site?")), |
|
111 | + $viewerGroupsField = ListboxField::create("ViewerGroups", _t('SilverStripe\\CMS\\Model\\SiteTree.VIEWERGROUPS', "Viewer Groups")) |
|
112 | + ->setSource($groupsMap) |
|
113 | + ->setAttribute( |
|
114 | + 'data-placeholder', |
|
115 | + _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
116 | + ), |
|
117 | + $editorsOptionsField = new OptionsetField("CanEditType", _t('SilverStripe\\SiteConfig\\SiteConfig.EDITHEADER', "Who can edit pages on this site?")), |
|
118 | + $editorGroupsField = ListboxField::create("EditorGroups", _t('SilverStripe\\CMS\\Model\\SiteTree.EDITORGROUPS', "Editor Groups")) |
|
119 | + ->setSource($groupsMap) |
|
120 | + ->setAttribute( |
|
121 | + 'data-placeholder', |
|
122 | + _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
123 | + ), |
|
124 | + $topLevelCreatorsOptionsField = new OptionsetField("CanCreateTopLevelType", _t('SilverStripe\\SiteConfig\\SiteConfig.TOPLEVELCREATE', "Who can create pages in the root of the site?")), |
|
125 | + $topLevelCreatorsGroupsField = ListboxField::create("CreateTopLevelGroups", _t(__CLASS__.'.TOPLEVELCREATORGROUPS', "Top level creators")) |
|
126 | + ->setSource($groupsMap) |
|
127 | + ->setAttribute( |
|
128 | + 'data-placeholder', |
|
129 | + _t('SilverStripe\\CMS\\Model\\SiteTree.GroupPlaceholder', 'Click to select group') |
|
130 | + ) |
|
131 | + ) |
|
132 | + ), |
|
133 | + new HiddenField('ID') |
|
134 | + ); |
|
135 | + |
|
136 | + $viewersOptionsSource = array(); |
|
137 | + $viewersOptionsSource["Anyone"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSANYONE', "Anyone"); |
|
138 | + $viewersOptionsSource["LoggedInUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSLOGGEDIN', "Logged-in users"); |
|
139 | + $viewersOptionsSource["OnlyTheseUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)"); |
|
140 | + $viewersOptionsField->setSource($viewersOptionsSource); |
|
141 | + |
|
142 | + if ($viewAllGroupsMap) { |
|
143 | + $viewerGroupsField->setDescription(_t( |
|
144 | + 'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC', |
|
145 | + 'Groups with global view permissions: {groupList}', |
|
146 | + ['groupList' => implode(', ', array_values($viewAllGroupsMap))] |
|
147 | + )); |
|
148 | + } |
|
149 | + |
|
150 | + if ($editAllGroupsMap) { |
|
151 | + $editorGroupsField->setDescription(_t( |
|
152 | + 'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC', |
|
153 | + 'Groups with global edit permissions: {groupList}', |
|
154 | + ['groupList' => implode(', ', array_values($editAllGroupsMap))] |
|
155 | + )); |
|
156 | + } |
|
157 | + |
|
158 | + $editorsOptionsSource = array(); |
|
159 | + $editorsOptionsSource["LoggedInUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); |
|
160 | + $editorsOptionsSource["OnlyTheseUsers"] = _t('SilverStripe\\CMS\\Model\\SiteTree.EDITONLYTHESE', "Only these groups (choose from list)"); |
|
161 | + $editorsOptionsField->setSource($editorsOptionsSource); |
|
162 | + |
|
163 | + $topLevelCreatorsOptionsField->setSource($editorsOptionsSource); |
|
164 | + |
|
165 | + if (!Permission::check('EDIT_SITECONFIG')) { |
|
166 | + $fields->makeFieldReadonly($viewersOptionsField); |
|
167 | + $fields->makeFieldReadonly($viewerGroupsField); |
|
168 | + $fields->makeFieldReadonly($editorsOptionsField); |
|
169 | + $fields->makeFieldReadonly($editorGroupsField); |
|
170 | + $fields->makeFieldReadonly($topLevelCreatorsOptionsField); |
|
171 | + $fields->makeFieldReadonly($topLevelCreatorsGroupsField); |
|
172 | + $fields->makeFieldReadonly($taglineField); |
|
173 | + $fields->makeFieldReadonly($titleField); |
|
174 | + } |
|
175 | + |
|
176 | + if (file_exists(BASE_PATH . '/install.php')) { |
|
177 | + $fields->addFieldToTab( |
|
178 | + "Root.Main", |
|
179 | + new LiteralField( |
|
180 | + "InstallWarningHeader", |
|
181 | + "<p class=\"message warning\">" . _t( |
|
182 | + "SilverStripe\\CMS\\Model\\SiteTree.REMOVE_INSTALL_WARNING", |
|
183 | + "Warning: You should remove install.php from this SilverStripe install for security reasons." |
|
184 | + ) . "</p>" |
|
185 | + ), |
|
186 | + "Title" |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + $tabMain->setTitle(_t('SilverStripe\\SiteConfig\\SiteConfig.TABMAIN', "Main")); |
|
191 | + $tabAccess->setTitle(_t('SilverStripe\\SiteConfig\\SiteConfig.TABACCESS', "Access")); |
|
192 | + $this->extend('updateCMSFields', $fields); |
|
193 | + |
|
194 | + return $fields; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get the actions that are sent to the CMS. |
|
199 | + * |
|
200 | + * In your extensions: updateEditFormActions($actions) |
|
201 | + * |
|
202 | + * @return FieldList |
|
203 | + */ |
|
204 | + public function getCMSActions() |
|
205 | + { |
|
206 | + if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) { |
|
207 | + $actions = new FieldList( |
|
208 | + FormAction::create( |
|
209 | + 'save_siteconfig', |
|
210 | + _t('SilverStripe\\CMS\\Controllers\\CMSMain.SAVE', 'Save') |
|
211 | + )->addExtraClass('btn-primary font-icon-save') |
|
212 | + ); |
|
213 | + } else { |
|
214 | + $actions = new FieldList(); |
|
215 | + } |
|
216 | + |
|
217 | + $this->extend('updateCMSActions', $actions); |
|
218 | + |
|
219 | + return $actions; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function CMSEditLink() |
|
226 | + { |
|
227 | + return SiteConfigLeftAndMain::singleton()->Link(); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Get the current sites SiteConfig, and creates a new one through |
|
232 | + * {@link make_site_config()} if none is found. |
|
233 | + * |
|
234 | + * @return SiteConfig |
|
235 | + */ |
|
236 | + public static function current_site_config() |
|
237 | + { |
|
238 | + /** @var SiteConfig $siteConfig */ |
|
239 | + $siteConfig = DataObject::get_one(SiteConfig::class); |
|
240 | + if ($siteConfig) { |
|
241 | + return $siteConfig; |
|
242 | + } |
|
243 | + |
|
244 | + return self::make_site_config(); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Setup a default SiteConfig record if none exists. |
|
249 | + */ |
|
250 | + public function requireDefaultRecords() |
|
251 | + { |
|
252 | + parent::requireDefaultRecords(); |
|
253 | + |
|
254 | + $config = DataObject::get_one(SiteConfig::class); |
|
255 | + |
|
256 | + if (!$config) { |
|
257 | + self::make_site_config(); |
|
258 | + |
|
259 | + DB::alteration_message("Added default site config", "created"); |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Create SiteConfig with defaults from language file. |
|
265 | + * |
|
266 | + * @return SiteConfig |
|
267 | + */ |
|
268 | + public static function make_site_config() |
|
269 | + { |
|
270 | + $config = SiteConfig::create(); |
|
271 | + $config->write(); |
|
272 | + |
|
273 | + return $config; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Can a user view this SiteConfig instance? |
|
278 | + * |
|
279 | + * @param Member $member |
|
280 | + * @return boolean |
|
281 | + */ |
|
282 | + public function canView($member = null) |
|
283 | + { |
|
284 | + if (!$member) { |
|
285 | + $member = Security::getCurrentUser(); |
|
286 | + } |
|
287 | + |
|
288 | + $extended = $this->extendedCan('canView', $member); |
|
289 | + if ($extended !== null) { |
|
290 | + return $extended; |
|
291 | + } |
|
292 | + |
|
293 | + // Assuming all that can edit this object can also view it |
|
294 | + return $this->canEdit($member); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Can a user view pages on this site? This method is only |
|
299 | + * called if a page is set to Inherit, but there is nothing |
|
300 | + * to inherit from. |
|
301 | + * |
|
302 | + * @param Member $member |
|
303 | + * @return boolean |
|
304 | + */ |
|
305 | + public function canViewPages($member = null) |
|
306 | + { |
|
307 | + if (!$member) { |
|
308 | + $member = Security::getCurrentUser(); |
|
309 | + } |
|
310 | + |
|
311 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
312 | + return true; |
|
313 | + } |
|
314 | + |
|
315 | + $extended = $this->extendedCan('canViewPages', $member); |
|
316 | + if ($extended !== null) { |
|
317 | + return $extended; |
|
318 | + } |
|
319 | + |
|
320 | + if (!$this->CanViewType || $this->CanViewType == 'Anyone') { |
|
321 | + return true; |
|
322 | + } |
|
323 | + |
|
324 | + // check for any logged-in users |
|
325 | + if ($this->CanViewType === 'LoggedInUsers' && $member) { |
|
326 | + return true; |
|
327 | + } |
|
328 | + |
|
329 | + // check for specific groups |
|
330 | + if ($this->CanViewType === 'OnlyTheseUsers' && $member && $member->inGroups($this->ViewerGroups())) { |
|
331 | + return true; |
|
332 | + } |
|
333 | + |
|
334 | + return false; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Can a user edit pages on this site? This method is only |
|
339 | + * called if a page is set to Inherit, but there is nothing |
|
340 | + * to inherit from, or on new records without a parent. |
|
341 | + * |
|
342 | + * @param Member $member |
|
343 | + * @return boolean |
|
344 | + */ |
|
345 | + public function canEditPages($member = null) |
|
346 | + { |
|
347 | + if (!$member) { |
|
348 | + $member = Security::getCurrentUser(); |
|
349 | + } |
|
350 | + |
|
351 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
352 | + return true; |
|
353 | + } |
|
354 | + |
|
355 | + $extended = $this->extendedCan('canEditPages', $member); |
|
356 | + if ($extended !== null) { |
|
357 | + return $extended; |
|
358 | + } |
|
359 | + |
|
360 | + // check for any logged-in users with CMS access |
|
361 | + if ($this->CanEditType === 'LoggedInUsers' |
|
362 | + && Permission::checkMember($member, $this->config()->get('required_permission')) |
|
363 | + ) { |
|
364 | + return true; |
|
365 | + } |
|
366 | + |
|
367 | + // check for specific groups |
|
368 | + if ($this->CanEditType === 'OnlyTheseUsers' && $member && $member->inGroups($this->EditorGroups())) { |
|
369 | + return true; |
|
370 | + } |
|
371 | + |
|
372 | + return false; |
|
373 | + } |
|
374 | + |
|
375 | + public function canEdit($member = null) |
|
376 | + { |
|
377 | + if (!$member) { |
|
378 | + $member = Security::getCurrentUser(); |
|
379 | + } |
|
380 | + |
|
381 | + $extended = $this->extendedCan('canEdit', $member); |
|
382 | + if ($extended !== null) { |
|
383 | + return $extended; |
|
384 | + } |
|
385 | + |
|
386 | + return Permission::checkMember($member, "EDIT_SITECONFIG"); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @return array |
|
391 | + */ |
|
392 | + public function providePermissions() |
|
393 | + { |
|
394 | + return array( |
|
395 | + 'EDIT_SITECONFIG' => array( |
|
396 | + 'name' => _t('SilverStripe\\SiteConfig\\SiteConfig.EDIT_PERMISSION', 'Manage site configuration'), |
|
397 | + 'category' => _t('SilverStripe\\Security\\Permission.PERMISSIONS_CATEGORY', 'Roles and access permissions'), |
|
398 | + 'help' => _t('SilverStripe\\SiteConfig\\SiteConfig.EDIT_PERMISSION_HELP', 'Ability to edit global access settings/top-level page permissions.'), |
|
399 | + 'sort' => 400 |
|
400 | + ) |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Can a user create pages in the root of this site? |
|
406 | + * |
|
407 | + * @param Member $member |
|
408 | + * @return boolean |
|
409 | + */ |
|
410 | + public function canCreateTopLevel($member = null) |
|
411 | + { |
|
412 | + if (!$member) { |
|
413 | + $member = Security::getCurrentUser(); |
|
414 | + } |
|
415 | + |
|
416 | + if ($member && Permission::checkMember($member, "ADMIN")) { |
|
417 | + return true; |
|
418 | + } |
|
419 | + |
|
420 | + $extended = $this->extendedCan('canCreateTopLevel', $member); |
|
421 | + if ($extended !== null) { |
|
422 | + return $extended; |
|
423 | + } |
|
424 | + |
|
425 | + // check for any logged-in users with CMS permission |
|
426 | + if ($this->CanCreateTopLevelType === 'LoggedInUsers' |
|
427 | + && Permission::checkMember($member, $this->config()->get('required_permission')) |
|
428 | + ) { |
|
429 | + return true; |
|
430 | + } |
|
431 | + |
|
432 | + // check for specific groups |
|
433 | + if ($this->CanCreateTopLevelType === 'OnlyTheseUsers' |
|
434 | + && $member |
|
435 | + && $member->inGroups($this->CreateTopLevelGroups()) |
|
436 | + ) { |
|
437 | + return true; |
|
438 | + } |
|
439 | + |
|
440 | + return false; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Add $SiteConfig to all SSViewers |
|
445 | + */ |
|
446 | + public static function get_template_global_variables() |
|
447 | + { |
|
448 | + return array( |
|
449 | + 'SiteConfig' => 'current_site_config', |
|
450 | + ); |
|
451 | + } |
|
452 | 452 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getCMSFields() |
86 | 86 | { |
87 | - $mapFn = function ($groups = []) { |
|
87 | + $mapFn = function($groups = []) { |
|
88 | 88 | $map = []; |
89 | 89 | foreach ($groups as $group) { |
90 | 90 | // Listboxfield values are escaped, use ASCII char instead of » |
@@ -173,15 +173,15 @@ discard block |
||
173 | 173 | $fields->makeFieldReadonly($titleField); |
174 | 174 | } |
175 | 175 | |
176 | - if (file_exists(BASE_PATH . '/install.php')) { |
|
176 | + if (file_exists(BASE_PATH.'/install.php')) { |
|
177 | 177 | $fields->addFieldToTab( |
178 | 178 | "Root.Main", |
179 | 179 | new LiteralField( |
180 | 180 | "InstallWarningHeader", |
181 | - "<p class=\"message warning\">" . _t( |
|
181 | + "<p class=\"message warning\">"._t( |
|
182 | 182 | "SilverStripe\\CMS\\Model\\SiteTree.REMOVE_INSTALL_WARNING", |
183 | 183 | "Warning: You should remove install.php from this SilverStripe install for security reasons." |
184 | - ) . "</p>" |
|
184 | + )."</p>" |
|
185 | 185 | ), |
186 | 186 | "Title" |
187 | 187 | ); |
@@ -139,7 +139,7 @@ |
||
139 | 139 | * |
140 | 140 | * @param array $data |
141 | 141 | * @param Form $form |
142 | - * @return String |
|
142 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
143 | 143 | */ |
144 | 144 | public function save_siteconfig($data, $form) |
145 | 145 | { |
@@ -16,148 +16,148 @@ |
||
16 | 16 | |
17 | 17 | class SiteConfigLeftAndMain extends LeftAndMain |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - private static $url_segment = 'settings'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private static $url_rule = '/$Action/$ID/$OtherID'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var int |
|
31 | - */ |
|
32 | - private static $menu_priority = -1; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private static $menu_title = 'Settings'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private static $menu_icon_class = 'font-icon-cog'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private static $tree_class = 'SilverStripe\\SiteConfig\\SiteConfig'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - private static $required_permission_codes = array('EDIT_SITECONFIG'); |
|
53 | - |
|
54 | - /** |
|
55 | - * Initialises the {@link SiteConfig} controller. |
|
56 | - */ |
|
57 | - public function init() |
|
58 | - { |
|
59 | - parent::init(); |
|
60 | - if (class_exists(SiteTree::class)) { |
|
61 | - Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js'); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param null $id Not used. |
|
67 | - * @param null $fields Not used. |
|
68 | - * |
|
69 | - * @return Form |
|
70 | - */ |
|
71 | - public function getEditForm($id = null, $fields = null) |
|
72 | - { |
|
73 | - $siteConfig = SiteConfig::current_site_config(); |
|
74 | - $fields = $siteConfig->getCMSFields(); |
|
75 | - |
|
76 | - // Tell the CMS what URL the preview should show |
|
77 | - $home = Director::absoluteBaseURL(); |
|
78 | - $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
|
79 | - |
|
80 | - // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
|
81 | - /** @skipUpgrade */ |
|
82 | - $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); |
|
83 | - $navField->setAllowHTML(true); |
|
84 | - |
|
85 | - // Retrieve validator, if one has been setup (e.g. via data extensions). |
|
86 | - if ($siteConfig->hasMethod("getCMSValidator")) { |
|
87 | - $validator = $siteConfig->getCMSValidator(); |
|
88 | - } else { |
|
89 | - $validator = null; |
|
90 | - } |
|
91 | - |
|
92 | - $actions = $siteConfig->getCMSActions(); |
|
93 | - $negotiator = $this->getResponseNegotiator(); |
|
94 | - /** @var Form $form */ |
|
95 | - $form = Form::create( |
|
96 | - $this, |
|
97 | - 'EditForm', |
|
98 | - $fields, |
|
99 | - $actions, |
|
100 | - $validator |
|
101 | - )->setHTMLID('Form_EditForm'); |
|
102 | - $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
|
103 | - $request = $this->getRequest(); |
|
104 | - if ($request->isAjax() && $negotiator) { |
|
105 | - $result = $form->forTemplate(); |
|
106 | - return $negotiator->respond($request, array( |
|
107 | - 'CurrentForm' => function () use ($result) { |
|
108 | - return $result; |
|
109 | - } |
|
110 | - )); |
|
111 | - } |
|
112 | - }); |
|
113 | - $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
|
114 | - $form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
|
115 | - |
|
116 | - if ($form->Fields()->hasTabSet()) { |
|
117 | - $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
|
118 | - } |
|
119 | - $form->setHTMLID('Form_EditForm'); |
|
120 | - $form->loadDataFrom($siteConfig); |
|
121 | - $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
|
122 | - |
|
123 | - // Use <button> to allow full jQuery UI styling |
|
124 | - $actions = $actions->dataFields(); |
|
125 | - if ($actions) { |
|
126 | - /** @var FormAction $action */ |
|
127 | - foreach ($actions as $action) { |
|
128 | - $action->setUseButtonTag(true); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - $this->extend('updateEditForm', $form); |
|
133 | - |
|
134 | - return $form; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Save the current sites {@link SiteConfig} into the database. |
|
139 | - * |
|
140 | - * @param array $data |
|
141 | - * @param Form $form |
|
142 | - * @return String |
|
143 | - */ |
|
144 | - public function save_siteconfig($data, $form) |
|
145 | - { |
|
146 | - $siteConfig = SiteConfig::current_site_config(); |
|
147 | - $form->saveInto($siteConfig); |
|
148 | - $siteConfig->write(); |
|
149 | - $this->response->addHeader('X-Status', rawurlencode(_t('SilverStripe\\Admin\\LeftAndMain.SAVEDUP', 'Saved.'))); |
|
150 | - return $form->forTemplate(); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function Breadcrumbs($unlinked = false) |
|
155 | - { |
|
156 | - return new ArrayList(array( |
|
157 | - new ArrayData(array( |
|
158 | - 'Title' => static::menu_title(), |
|
159 | - 'Link' => $this->Link() |
|
160 | - )) |
|
161 | - )); |
|
162 | - } |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + private static $url_segment = 'settings'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private static $url_rule = '/$Action/$ID/$OtherID'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var int |
|
31 | + */ |
|
32 | + private static $menu_priority = -1; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private static $menu_title = 'Settings'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private static $menu_icon_class = 'font-icon-cog'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private static $tree_class = 'SilverStripe\\SiteConfig\\SiteConfig'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + private static $required_permission_codes = array('EDIT_SITECONFIG'); |
|
53 | + |
|
54 | + /** |
|
55 | + * Initialises the {@link SiteConfig} controller. |
|
56 | + */ |
|
57 | + public function init() |
|
58 | + { |
|
59 | + parent::init(); |
|
60 | + if (class_exists(SiteTree::class)) { |
|
61 | + Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js'); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param null $id Not used. |
|
67 | + * @param null $fields Not used. |
|
68 | + * |
|
69 | + * @return Form |
|
70 | + */ |
|
71 | + public function getEditForm($id = null, $fields = null) |
|
72 | + { |
|
73 | + $siteConfig = SiteConfig::current_site_config(); |
|
74 | + $fields = $siteConfig->getCMSFields(); |
|
75 | + |
|
76 | + // Tell the CMS what URL the preview should show |
|
77 | + $home = Director::absoluteBaseURL(); |
|
78 | + $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
|
79 | + |
|
80 | + // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
|
81 | + /** @skipUpgrade */ |
|
82 | + $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); |
|
83 | + $navField->setAllowHTML(true); |
|
84 | + |
|
85 | + // Retrieve validator, if one has been setup (e.g. via data extensions). |
|
86 | + if ($siteConfig->hasMethod("getCMSValidator")) { |
|
87 | + $validator = $siteConfig->getCMSValidator(); |
|
88 | + } else { |
|
89 | + $validator = null; |
|
90 | + } |
|
91 | + |
|
92 | + $actions = $siteConfig->getCMSActions(); |
|
93 | + $negotiator = $this->getResponseNegotiator(); |
|
94 | + /** @var Form $form */ |
|
95 | + $form = Form::create( |
|
96 | + $this, |
|
97 | + 'EditForm', |
|
98 | + $fields, |
|
99 | + $actions, |
|
100 | + $validator |
|
101 | + )->setHTMLID('Form_EditForm'); |
|
102 | + $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
|
103 | + $request = $this->getRequest(); |
|
104 | + if ($request->isAjax() && $negotiator) { |
|
105 | + $result = $form->forTemplate(); |
|
106 | + return $negotiator->respond($request, array( |
|
107 | + 'CurrentForm' => function () use ($result) { |
|
108 | + return $result; |
|
109 | + } |
|
110 | + )); |
|
111 | + } |
|
112 | + }); |
|
113 | + $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
|
114 | + $form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
|
115 | + |
|
116 | + if ($form->Fields()->hasTabSet()) { |
|
117 | + $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
|
118 | + } |
|
119 | + $form->setHTMLID('Form_EditForm'); |
|
120 | + $form->loadDataFrom($siteConfig); |
|
121 | + $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
|
122 | + |
|
123 | + // Use <button> to allow full jQuery UI styling |
|
124 | + $actions = $actions->dataFields(); |
|
125 | + if ($actions) { |
|
126 | + /** @var FormAction $action */ |
|
127 | + foreach ($actions as $action) { |
|
128 | + $action->setUseButtonTag(true); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + $this->extend('updateEditForm', $form); |
|
133 | + |
|
134 | + return $form; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Save the current sites {@link SiteConfig} into the database. |
|
139 | + * |
|
140 | + * @param array $data |
|
141 | + * @param Form $form |
|
142 | + * @return String |
|
143 | + */ |
|
144 | + public function save_siteconfig($data, $form) |
|
145 | + { |
|
146 | + $siteConfig = SiteConfig::current_site_config(); |
|
147 | + $form->saveInto($siteConfig); |
|
148 | + $siteConfig->write(); |
|
149 | + $this->response->addHeader('X-Status', rawurlencode(_t('SilverStripe\\Admin\\LeftAndMain.SAVEDUP', 'Saved.'))); |
|
150 | + return $form->forTemplate(); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function Breadcrumbs($unlinked = false) |
|
155 | + { |
|
156 | + return new ArrayList(array( |
|
157 | + new ArrayData(array( |
|
158 | + 'Title' => static::menu_title(), |
|
159 | + 'Link' => $this->Link() |
|
160 | + )) |
|
161 | + )); |
|
162 | + } |
|
163 | 163 | } |
@@ -99,12 +99,12 @@ |
||
99 | 99 | $actions, |
100 | 100 | $validator |
101 | 101 | )->setHTMLID('Form_EditForm'); |
102 | - $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
|
102 | + $form->setValidationResponseCallback(function(ValidationResult $errors) use ($negotiator, $form) { |
|
103 | 103 | $request = $this->getRequest(); |
104 | 104 | if ($request->isAjax() && $negotiator) { |
105 | 105 | $result = $form->forTemplate(); |
106 | 106 | return $negotiator->respond($request, array( |
107 | - 'CurrentForm' => function () use ($result) { |
|
107 | + 'CurrentForm' => function() use ($result) { |
|
108 | 108 | return $result; |
109 | 109 | } |
110 | 110 | )); |
@@ -10,48 +10,48 @@ |
||
10 | 10 | */ |
11 | 11 | class SiteConfigPagePermissions implements DefaultPermissionChecker |
12 | 12 | { |
13 | - /** |
|
14 | - * Can root be edited? |
|
15 | - * |
|
16 | - * @param Member $member |
|
17 | - * @return bool |
|
18 | - */ |
|
19 | - public function canEdit(Member $member = null) |
|
20 | - { |
|
21 | - return SiteConfig::current_site_config()->canEditPages($member); |
|
22 | - } |
|
13 | + /** |
|
14 | + * Can root be edited? |
|
15 | + * |
|
16 | + * @param Member $member |
|
17 | + * @return bool |
|
18 | + */ |
|
19 | + public function canEdit(Member $member = null) |
|
20 | + { |
|
21 | + return SiteConfig::current_site_config()->canEditPages($member); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Can root be viewed? |
|
26 | - * |
|
27 | - * @param Member $member |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - public function canView(Member $member = null) |
|
31 | - { |
|
32 | - return SiteConfig::current_site_config()->canViewPages($member); |
|
33 | - } |
|
24 | + /** |
|
25 | + * Can root be viewed? |
|
26 | + * |
|
27 | + * @param Member $member |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + public function canView(Member $member = null) |
|
31 | + { |
|
32 | + return SiteConfig::current_site_config()->canViewPages($member); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Can root be deleted? |
|
37 | - * |
|
38 | - * @param Member $member |
|
39 | - * @return bool |
|
40 | - */ |
|
41 | - public function canDelete(Member $member = null) |
|
42 | - { |
|
43 | - // Same as canEdit |
|
44 | - return $this->canEdit($member); |
|
45 | - } |
|
35 | + /** |
|
36 | + * Can root be deleted? |
|
37 | + * |
|
38 | + * @param Member $member |
|
39 | + * @return bool |
|
40 | + */ |
|
41 | + public function canDelete(Member $member = null) |
|
42 | + { |
|
43 | + // Same as canEdit |
|
44 | + return $this->canEdit($member); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Can root objects be created? |
|
49 | - * |
|
50 | - * @param Member $member |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function canCreate(Member $member = null) |
|
54 | - { |
|
55 | - return SiteConfig::current_site_config()->canCreateTopLevel(); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Can root objects be created? |
|
49 | + * |
|
50 | + * @param Member $member |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function canCreate(Member $member = null) |
|
54 | + { |
|
55 | + return SiteConfig::current_site_config()->canCreateTopLevel(); |
|
56 | + } |
|
57 | 57 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!defined('BASE_PATH')) { |
4 | - define('BASE_PATH', getcwd()); |
|
4 | + define('BASE_PATH', getcwd()); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | require_once BASE_PATH . '/cms/tests/bootstrap/mysite.php'; |
@@ -4,6 +4,6 @@ |
||
4 | 4 | define('BASE_PATH', getcwd()); |
5 | 5 | } |
6 | 6 | |
7 | -require_once BASE_PATH . '/cms/tests/bootstrap/mysite.php'; |
|
7 | +require_once BASE_PATH.'/cms/tests/bootstrap/mysite.php'; |
|
8 | 8 | |
9 | -copy(__DIR__ . '/fixtures/theme.yml.fixture', $projectPath . '/_config/dummytheme.yml'); |
|
9 | +copy(__DIR__.'/fixtures/theme.yml.fixture', $projectPath.'/_config/dummytheme.yml'); |
@@ -12,59 +12,59 @@ |
||
12 | 12 | */ |
13 | 13 | class SiteConfigTest extends SapphireTest |
14 | 14 | { |
15 | - protected static $fixture_file = 'SiteConfigTest.yml'; |
|
15 | + protected static $fixture_file = 'SiteConfigTest.yml'; |
|
16 | 16 | |
17 | - protected static $illegal_extensions = array( |
|
18 | - SiteTree::class => array('SiteTreeSubsites'), |
|
19 | - ); |
|
17 | + protected static $illegal_extensions = array( |
|
18 | + SiteTree::class => array('SiteTreeSubsites'), |
|
19 | + ); |
|
20 | 20 | |
21 | - public function testCanCreateRootPages() |
|
22 | - { |
|
23 | - /** @var SiteConfig $config */ |
|
24 | - $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
21 | + public function testCanCreateRootPages() |
|
22 | + { |
|
23 | + /** @var SiteConfig $config */ |
|
24 | + $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
25 | 25 | |
26 | - // Log in without pages admin access |
|
27 | - $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
28 | - $this->assertFalse($config->canCreateTopLevel()); |
|
26 | + // Log in without pages admin access |
|
27 | + $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
28 | + $this->assertFalse($config->canCreateTopLevel()); |
|
29 | 29 | |
30 | - // Login with necessary edit permission |
|
31 | - $perms = SiteConfig::config()->get('required_permission'); |
|
32 | - $this->logInWithPermission(reset($perms)); |
|
33 | - $this->assertTrue($config->canCreateTopLevel()); |
|
34 | - } |
|
30 | + // Login with necessary edit permission |
|
31 | + $perms = SiteConfig::config()->get('required_permission'); |
|
32 | + $this->logInWithPermission(reset($perms)); |
|
33 | + $this->assertTrue($config->canCreateTopLevel()); |
|
34 | + } |
|
35 | 35 | |
36 | - public function testCanViewPages() |
|
37 | - { |
|
38 | - /** @var SiteConfig $config */ |
|
39 | - $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
40 | - $this->assertTrue($config->canViewPages()); |
|
41 | - } |
|
36 | + public function testCanViewPages() |
|
37 | + { |
|
38 | + /** @var SiteConfig $config */ |
|
39 | + $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
40 | + $this->assertTrue($config->canViewPages()); |
|
41 | + } |
|
42 | 42 | |
43 | - public function testCanEdit() |
|
44 | - { |
|
45 | - $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
43 | + public function testCanEdit() |
|
44 | + { |
|
45 | + $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
46 | 46 | |
47 | - // Unrelated permissions don't allow siteconfig |
|
48 | - $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
49 | - $this->assertFalse($config->canEdit()); |
|
47 | + // Unrelated permissions don't allow siteconfig |
|
48 | + $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
49 | + $this->assertFalse($config->canEdit()); |
|
50 | 50 | |
51 | - // Only those with edit permission can do this |
|
52 | - $this->logInWithPermission('EDIT_SITECONFIG'); |
|
53 | - $this->assertTrue($config->canEdit()); |
|
54 | - } |
|
51 | + // Only those with edit permission can do this |
|
52 | + $this->logInWithPermission('EDIT_SITECONFIG'); |
|
53 | + $this->assertTrue($config->canEdit()); |
|
54 | + } |
|
55 | 55 | |
56 | - public function testCanEditPages() |
|
57 | - { |
|
58 | - /** @var SiteConfig $config */ |
|
59 | - $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
56 | + public function testCanEditPages() |
|
57 | + { |
|
58 | + /** @var SiteConfig $config */ |
|
59 | + $config = $this->objFromFixture(SiteConfig::class, 'default'); |
|
60 | 60 | |
61 | - // Log in without pages admin access |
|
62 | - $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
63 | - $this->assertFalse($config->canEditPages()); |
|
61 | + // Log in without pages admin access |
|
62 | + $this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
|
63 | + $this->assertFalse($config->canEditPages()); |
|
64 | 64 | |
65 | - // Login with necessary edit permission |
|
66 | - $perms = SiteConfig::config()->get('required_permission'); |
|
67 | - $this->logInWithPermission(reset($perms)); |
|
68 | - $this->assertTrue($config->canEditPages()); |
|
69 | - } |
|
65 | + // Login with necessary edit permission |
|
66 | + $perms = SiteConfig::config()->get('required_permission'); |
|
67 | + $this->logInWithPermission(reset($perms)); |
|
68 | + $this->assertTrue($config->canEditPages()); |
|
69 | + } |
|
70 | 70 | } |