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