@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getCMSFields() |
201 | 201 | { |
202 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
202 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
203 | 203 | $fields->addFieldsToTab( |
204 | 204 | 'Root.Main', |
205 | 205 | [ |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $url = $this->Website; |
304 | 304 | |
305 | 305 | if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
306 | - $url = 'http://' . $url; |
|
306 | + $url = 'http://'.$url; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | $this->extend('updateWebsiteURL', $url); |
@@ -31,283 +31,283 @@ |
||
31 | 31 | */ |
32 | 32 | class LocationPage extends \Page implements PermissionProvider |
33 | 33 | { |
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private static $singular_name = 'Location'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private static $plural_name = 'Locations'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private static $db = [ |
|
48 | - 'Featured' => 'Boolean', |
|
49 | - 'Website' => 'Varchar(255)', |
|
50 | - 'Phone' => 'Varchar(40)', |
|
51 | - 'Email' => 'Varchar(255)', |
|
52 | - 'Fax' => 'Varchar(45)', |
|
53 | - 'Import_ID' => 'Int', |
|
54 | - 'LegacyObjectID' => 'Int', |
|
55 | - ]; |
|
56 | - |
|
57 | - private static $many_many = [ |
|
58 | - 'Categories' => LocationCategory::class, |
|
59 | - ]; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string |
|
63 | - */ |
|
64 | - private static $table_name = 'LocationPage'; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private static $casting = [ |
|
70 | - 'distance' => 'Decimal(9,3)', |
|
71 | - ]; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var int[] |
|
75 | - */ |
|
76 | - private static $defaults = [ |
|
77 | - 'ShowInMenus' => 0, |
|
78 | - ]; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - private static $default_sort = 'Title'; |
|
84 | - |
|
85 | - /** |
|
86 | - * api access via Restful Server module |
|
87 | - * |
|
88 | - * @var bool |
|
89 | - */ |
|
90 | - private static $api_access = true; |
|
91 | - |
|
92 | - /** |
|
93 | - * search fields for Model Admin |
|
94 | - * |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - private static $searchable_fields = [ |
|
98 | - 'Title', |
|
99 | - 'Address', |
|
100 | - 'City', |
|
101 | - 'State', |
|
102 | - 'PostalCode', |
|
103 | - 'Country', |
|
104 | - 'Website', |
|
105 | - 'Phone', |
|
106 | - 'Email', |
|
107 | - 'Featured', |
|
108 | - ]; |
|
109 | - |
|
110 | - /** |
|
111 | - * columns for grid field |
|
112 | - * |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - private static $summary_fields = [ |
|
116 | - 'Title', |
|
117 | - 'Address', |
|
118 | - 'Address2', |
|
119 | - 'City', |
|
120 | - 'State', |
|
121 | - 'PostalCode', |
|
122 | - 'CountryCode', |
|
123 | - 'Phone' => 'Phone', |
|
124 | - 'Fax' => 'Fax', |
|
125 | - 'Email' => 'Email', |
|
126 | - 'Website' => 'Website', |
|
127 | - 'Featured', |
|
128 | - 'CategoryList', |
|
129 | - 'Lat', |
|
130 | - 'Lng', |
|
131 | - 'Import_ID', |
|
132 | - ]; |
|
133 | - |
|
134 | - /** |
|
135 | - * @var bool |
|
136 | - */ |
|
137 | - private static $show_in_sitetree = false; |
|
138 | - |
|
139 | - /** |
|
140 | - * @var array |
|
141 | - */ |
|
142 | - private static $allowed_children = []; |
|
143 | - |
|
144 | - /** |
|
145 | - * Coords status for $summary_fields |
|
146 | - * |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function getCoords() |
|
150 | - { |
|
151 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function getCategoryList() |
|
158 | - { |
|
159 | - if ($this->Categories()->count()) { |
|
160 | - return implode(', ', $this->Categories()->column('Name')); |
|
161 | - } |
|
162 | - |
|
163 | - return ''; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return bool|string |
|
168 | - */ |
|
169 | - public function getCountryCode() |
|
170 | - { |
|
171 | - if ($this->Country) { |
|
172 | - return strtoupper($this->Country); |
|
173 | - } |
|
174 | - |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * custom labels for fields |
|
180 | - * |
|
181 | - * @param bool $includerelations |
|
182 | - * @return array|string |
|
183 | - */ |
|
184 | - public function fieldLabels($includerelations = true) |
|
185 | - { |
|
186 | - $labels = parent::fieldLabels($includerelations); |
|
187 | - |
|
188 | - $labels['Title'] = 'Name'; |
|
189 | - $labels['Address2'] = 'Address 2'; |
|
190 | - $labels['PostalCode'] = 'Postal Code'; |
|
191 | - $labels['Categories.Name'] = 'Categories'; |
|
192 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
193 | - |
|
194 | - return $labels; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @return FieldList |
|
199 | - */ |
|
200 | - public function getCMSFields() |
|
201 | - { |
|
202 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
203 | - $fields->addFieldsToTab( |
|
204 | - 'Root.Main', |
|
205 | - [ |
|
206 | - CheckboxField::create('Featured') |
|
207 | - ->setTitle('Featured'), |
|
208 | - ], |
|
209 | - 'Content' |
|
210 | - ); |
|
211 | - |
|
212 | - if ($this->exists()) { |
|
213 | - $fields->addFieldToTab( |
|
214 | - 'Root.Categories', |
|
215 | - GridField::create( |
|
216 | - 'Categories', |
|
217 | - 'Categories', |
|
218 | - $this->Categories(), |
|
219 | - $catConfig = GridFieldConfig_RelationEditor::create() |
|
220 | - ) |
|
221 | - ); |
|
222 | - |
|
223 | - $catConfig->removeComponentsByType([ |
|
224 | - GridFieldAddExistingAutocompleter::class, |
|
225 | - ])->addComponents([ |
|
226 | - new GridFieldAddExistingSearchButton() |
|
227 | - ]); |
|
228 | - } |
|
229 | - |
|
230 | - $fields->addFieldsToTab('Root.Contact', [ |
|
231 | - TextField::create('Website') |
|
232 | - ->setTitle('Website') |
|
233 | - ->setDescription('Include the http/https (example: https://google.com)'), |
|
234 | - TextField::create('Phone') |
|
235 | - ->setTitle('Phone'), |
|
236 | - EmailField::create('Email') |
|
237 | - ->setTitle('Email'), |
|
238 | - TextField::create('Fax') |
|
239 | - ->setTitle('Fax'), |
|
240 | - ]); |
|
241 | - }); |
|
242 | - |
|
243 | - return parent::getCMSFields(); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param null $member |
|
248 | - * @param array $context |
|
249 | - * @return bool |
|
250 | - */ |
|
251 | - public function canView($member = null, $context = []) |
|
252 | - { |
|
253 | - return true; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @param null $member |
|
258 | - * @param array $context |
|
259 | - * @return bool|int |
|
260 | - */ |
|
261 | - public function canEdit($member = null, $context = []) |
|
262 | - { |
|
263 | - return Permission::check('Location_EDIT', 'any', $member); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @param null $member |
|
268 | - * @param array $context |
|
269 | - * @return bool|int |
|
270 | - */ |
|
271 | - public function canDelete($member = null, $context = []) |
|
272 | - { |
|
273 | - return Permission::check('Location_DELETE', 'any', $member); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param null $member |
|
278 | - * @param array $context |
|
279 | - * @return bool|int |
|
280 | - */ |
|
281 | - public function canCreate($member = null, $context = []) |
|
282 | - { |
|
283 | - return Permission::check('Location_CREATE', 'any', $member); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @return array |
|
288 | - */ |
|
289 | - public function providePermissions() |
|
290 | - { |
|
291 | - return [ |
|
292 | - 'Location_EDIT' => 'Edit a Location', |
|
293 | - 'Location_DELETE' => 'Delete a Location', |
|
294 | - 'Location_CREATE' => 'Create a Location', |
|
295 | - ]; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function getWebsiteURL() |
|
302 | - { |
|
303 | - $url = $this->Website; |
|
304 | - |
|
305 | - if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
|
306 | - $url = 'http://' . $url; |
|
307 | - } |
|
308 | - |
|
309 | - $this->extend('updateWebsiteURL', $url); |
|
310 | - |
|
311 | - return $url; |
|
312 | - } |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private static $singular_name = 'Location'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private static $plural_name = 'Locations'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private static $db = [ |
|
48 | + 'Featured' => 'Boolean', |
|
49 | + 'Website' => 'Varchar(255)', |
|
50 | + 'Phone' => 'Varchar(40)', |
|
51 | + 'Email' => 'Varchar(255)', |
|
52 | + 'Fax' => 'Varchar(45)', |
|
53 | + 'Import_ID' => 'Int', |
|
54 | + 'LegacyObjectID' => 'Int', |
|
55 | + ]; |
|
56 | + |
|
57 | + private static $many_many = [ |
|
58 | + 'Categories' => LocationCategory::class, |
|
59 | + ]; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string |
|
63 | + */ |
|
64 | + private static $table_name = 'LocationPage'; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private static $casting = [ |
|
70 | + 'distance' => 'Decimal(9,3)', |
|
71 | + ]; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var int[] |
|
75 | + */ |
|
76 | + private static $defaults = [ |
|
77 | + 'ShowInMenus' => 0, |
|
78 | + ]; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + private static $default_sort = 'Title'; |
|
84 | + |
|
85 | + /** |
|
86 | + * api access via Restful Server module |
|
87 | + * |
|
88 | + * @var bool |
|
89 | + */ |
|
90 | + private static $api_access = true; |
|
91 | + |
|
92 | + /** |
|
93 | + * search fields for Model Admin |
|
94 | + * |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + private static $searchable_fields = [ |
|
98 | + 'Title', |
|
99 | + 'Address', |
|
100 | + 'City', |
|
101 | + 'State', |
|
102 | + 'PostalCode', |
|
103 | + 'Country', |
|
104 | + 'Website', |
|
105 | + 'Phone', |
|
106 | + 'Email', |
|
107 | + 'Featured', |
|
108 | + ]; |
|
109 | + |
|
110 | + /** |
|
111 | + * columns for grid field |
|
112 | + * |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + private static $summary_fields = [ |
|
116 | + 'Title', |
|
117 | + 'Address', |
|
118 | + 'Address2', |
|
119 | + 'City', |
|
120 | + 'State', |
|
121 | + 'PostalCode', |
|
122 | + 'CountryCode', |
|
123 | + 'Phone' => 'Phone', |
|
124 | + 'Fax' => 'Fax', |
|
125 | + 'Email' => 'Email', |
|
126 | + 'Website' => 'Website', |
|
127 | + 'Featured', |
|
128 | + 'CategoryList', |
|
129 | + 'Lat', |
|
130 | + 'Lng', |
|
131 | + 'Import_ID', |
|
132 | + ]; |
|
133 | + |
|
134 | + /** |
|
135 | + * @var bool |
|
136 | + */ |
|
137 | + private static $show_in_sitetree = false; |
|
138 | + |
|
139 | + /** |
|
140 | + * @var array |
|
141 | + */ |
|
142 | + private static $allowed_children = []; |
|
143 | + |
|
144 | + /** |
|
145 | + * Coords status for $summary_fields |
|
146 | + * |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function getCoords() |
|
150 | + { |
|
151 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function getCategoryList() |
|
158 | + { |
|
159 | + if ($this->Categories()->count()) { |
|
160 | + return implode(', ', $this->Categories()->column('Name')); |
|
161 | + } |
|
162 | + |
|
163 | + return ''; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool|string |
|
168 | + */ |
|
169 | + public function getCountryCode() |
|
170 | + { |
|
171 | + if ($this->Country) { |
|
172 | + return strtoupper($this->Country); |
|
173 | + } |
|
174 | + |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * custom labels for fields |
|
180 | + * |
|
181 | + * @param bool $includerelations |
|
182 | + * @return array|string |
|
183 | + */ |
|
184 | + public function fieldLabels($includerelations = true) |
|
185 | + { |
|
186 | + $labels = parent::fieldLabels($includerelations); |
|
187 | + |
|
188 | + $labels['Title'] = 'Name'; |
|
189 | + $labels['Address2'] = 'Address 2'; |
|
190 | + $labels['PostalCode'] = 'Postal Code'; |
|
191 | + $labels['Categories.Name'] = 'Categories'; |
|
192 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
193 | + |
|
194 | + return $labels; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @return FieldList |
|
199 | + */ |
|
200 | + public function getCMSFields() |
|
201 | + { |
|
202 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
203 | + $fields->addFieldsToTab( |
|
204 | + 'Root.Main', |
|
205 | + [ |
|
206 | + CheckboxField::create('Featured') |
|
207 | + ->setTitle('Featured'), |
|
208 | + ], |
|
209 | + 'Content' |
|
210 | + ); |
|
211 | + |
|
212 | + if ($this->exists()) { |
|
213 | + $fields->addFieldToTab( |
|
214 | + 'Root.Categories', |
|
215 | + GridField::create( |
|
216 | + 'Categories', |
|
217 | + 'Categories', |
|
218 | + $this->Categories(), |
|
219 | + $catConfig = GridFieldConfig_RelationEditor::create() |
|
220 | + ) |
|
221 | + ); |
|
222 | + |
|
223 | + $catConfig->removeComponentsByType([ |
|
224 | + GridFieldAddExistingAutocompleter::class, |
|
225 | + ])->addComponents([ |
|
226 | + new GridFieldAddExistingSearchButton() |
|
227 | + ]); |
|
228 | + } |
|
229 | + |
|
230 | + $fields->addFieldsToTab('Root.Contact', [ |
|
231 | + TextField::create('Website') |
|
232 | + ->setTitle('Website') |
|
233 | + ->setDescription('Include the http/https (example: https://google.com)'), |
|
234 | + TextField::create('Phone') |
|
235 | + ->setTitle('Phone'), |
|
236 | + EmailField::create('Email') |
|
237 | + ->setTitle('Email'), |
|
238 | + TextField::create('Fax') |
|
239 | + ->setTitle('Fax'), |
|
240 | + ]); |
|
241 | + }); |
|
242 | + |
|
243 | + return parent::getCMSFields(); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param null $member |
|
248 | + * @param array $context |
|
249 | + * @return bool |
|
250 | + */ |
|
251 | + public function canView($member = null, $context = []) |
|
252 | + { |
|
253 | + return true; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @param null $member |
|
258 | + * @param array $context |
|
259 | + * @return bool|int |
|
260 | + */ |
|
261 | + public function canEdit($member = null, $context = []) |
|
262 | + { |
|
263 | + return Permission::check('Location_EDIT', 'any', $member); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @param null $member |
|
268 | + * @param array $context |
|
269 | + * @return bool|int |
|
270 | + */ |
|
271 | + public function canDelete($member = null, $context = []) |
|
272 | + { |
|
273 | + return Permission::check('Location_DELETE', 'any', $member); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param null $member |
|
278 | + * @param array $context |
|
279 | + * @return bool|int |
|
280 | + */ |
|
281 | + public function canCreate($member = null, $context = []) |
|
282 | + { |
|
283 | + return Permission::check('Location_CREATE', 'any', $member); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @return array |
|
288 | + */ |
|
289 | + public function providePermissions() |
|
290 | + { |
|
291 | + return [ |
|
292 | + 'Location_EDIT' => 'Edit a Location', |
|
293 | + 'Location_DELETE' => 'Delete a Location', |
|
294 | + 'Location_CREATE' => 'Create a Location', |
|
295 | + ]; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function getWebsiteURL() |
|
302 | + { |
|
303 | + $url = $this->Website; |
|
304 | + |
|
305 | + if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
|
306 | + $url = 'http://' . $url; |
|
307 | + } |
|
308 | + |
|
309 | + $this->extend('updateWebsiteURL', $url); |
|
310 | + |
|
311 | + return $url; |
|
312 | + } |
|
313 | 313 | } |