@@ -37,315 +37,315 @@ |
||
37 | 37 | */ |
38 | 38 | class SlideImage extends DataObject implements PermissionProvider |
39 | 39 | { |
40 | - /** |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - private static $singular_name = 'Slide'; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - private static $plural_name = 'Slides'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - private static $db = [ |
|
54 | - 'Name' => 'Varchar(255)', |
|
55 | - 'Headline' => 'Varchar(255)', |
|
56 | - 'Description' => 'Text', |
|
57 | - 'SortOrder' => 'Int', |
|
58 | - 'SlideType' => 'Varchar', |
|
59 | - ]; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - private static $has_one = [ |
|
65 | - 'Image' => Image::class, |
|
66 | - //'Video' => Embed::class, |
|
67 | - 'Page' => \Page::class, |
|
68 | - 'PageLink' => SiteTree::class, |
|
69 | - 'SlideLink' => Link::class, |
|
70 | - ]; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - private static $owns = [ |
|
76 | - 'Image', |
|
77 | - ]; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - private static $table_name = 'SlideImage'; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - private static $default_sort = 'SortOrder'; |
|
88 | - |
|
89 | - /** |
|
90 | - * Adds Publish button to SlideImage record |
|
91 | - * |
|
92 | - * @var bool |
|
93 | - */ |
|
94 | - private static $versioned_gridfield_extensions = true; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - private static $defaults = [ |
|
100 | - 'SlideType' => 'Image', |
|
101 | - ]; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var array |
|
105 | - */ |
|
106 | - private static $summary_fields = [ |
|
107 | - 'Image.CMSThumbnail' => 'Image', |
|
108 | - 'Name' => 'Name', |
|
109 | - ]; |
|
110 | - |
|
111 | - /** |
|
112 | - * @var array |
|
113 | - */ |
|
114 | - private static $searchable_fields = [ |
|
115 | - 'Name', |
|
116 | - 'Headline', |
|
117 | - 'Description', |
|
118 | - ]; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var int |
|
122 | - */ |
|
123 | - private static $image_size_limit = 512000; |
|
124 | - |
|
125 | - /** |
|
126 | - * @var array |
|
127 | - */ |
|
128 | - private static $slide_types = [ |
|
129 | - 'Image', |
|
130 | - 'Video', |
|
131 | - 'Text', |
|
132 | - ]; |
|
133 | - |
|
134 | - /** |
|
135 | - * @param bool $includerelations |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function fieldLabels($includerelations = true) |
|
139 | - { |
|
140 | - $labels = parent::fieldLabels($includerelations); |
|
141 | - |
|
142 | - $labels['Name'] = _t(__CLASS__ . '.NAME', 'Name'); |
|
143 | - $labels['Headline'] = _t(__CLASS__ . '.HEADLINE', 'Headline'); |
|
144 | - $labels['Description'] = _t(__CLASS__ . '.DESCRIPTION', 'Description'); |
|
145 | - $labels['SlideLinkID'] = _t(__CLASS__ . '.PAGE_LINK', "Call to action link"); |
|
146 | - $labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image'); |
|
147 | - $labels['SlideType'] = _t(__CLASS__ . '.SlideType', 'Image or Video'); |
|
148 | - $labels['Video'] = _t(__CLASS__ . '.VideoLabel', 'Video URL'); |
|
149 | - |
|
150 | - return $labels; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @return \SilverStripe\Forms\FieldList |
|
155 | - */ |
|
156 | - public function getCMSFields() |
|
157 | - { |
|
158 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
159 | - $fields->removeByName([ |
|
160 | - 'ShowSlide', |
|
161 | - 'SortOrder', |
|
162 | - 'PageID', |
|
163 | - 'Image', |
|
164 | - 'SlideType', |
|
165 | - 'Video', |
|
166 | - 'VideoID', |
|
167 | - 'SlideLinkID', |
|
168 | - ]); |
|
169 | - |
|
170 | - // Name |
|
171 | - $fields->dataFieldByName('Name') |
|
172 | - ->setDescription( |
|
173 | - _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only') |
|
174 | - ); |
|
175 | - |
|
176 | - // Headline |
|
177 | - $fields->dataFieldByName('Headline') |
|
178 | - ->setDescription( |
|
179 | - _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template') |
|
180 | - ); |
|
181 | - |
|
182 | - // Description |
|
183 | - $fields->dataFieldByName('Description') |
|
184 | - ->setDescription( |
|
185 | - _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template') |
|
186 | - ); |
|
187 | - |
|
188 | - // Page link |
|
189 | - $fields->replaceField( |
|
190 | - 'PageLinkID', |
|
191 | - LinkField::create('SlideLink', $this->fieldLabel('SlideLinkID'), $this) |
|
192 | - ); |
|
193 | - |
|
194 | - // Image |
|
195 | - $image = UploadField::create('Image', $this->fieldLabel('Image')) |
|
196 | - ->setFolderName('Uploads/SlideImages'); |
|
197 | - |
|
198 | - $image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']); |
|
199 | - |
|
200 | - $fields->addFieldToTab( |
|
201 | - 'Root.Main', |
|
202 | - CompositeField::create(FieldList::create( |
|
203 | - DropdownField::create('SlideType', $this->fieldLabel('SlideType')) |
|
204 | - ->setSource($this->getTypeSource()), |
|
205 | - Wrapper::create( |
|
206 | - $image |
|
207 | - )->displayIf('SlideType')->isEqualTo('Image')->orIf('SlideType')->isEqualTo('Video')->end(), |
|
208 | - /*Wrapper::create( |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + private static $singular_name = 'Slide'; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + private static $plural_name = 'Slides'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + private static $db = [ |
|
54 | + 'Name' => 'Varchar(255)', |
|
55 | + 'Headline' => 'Varchar(255)', |
|
56 | + 'Description' => 'Text', |
|
57 | + 'SortOrder' => 'Int', |
|
58 | + 'SlideType' => 'Varchar', |
|
59 | + ]; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + private static $has_one = [ |
|
65 | + 'Image' => Image::class, |
|
66 | + //'Video' => Embed::class, |
|
67 | + 'Page' => \Page::class, |
|
68 | + 'PageLink' => SiteTree::class, |
|
69 | + 'SlideLink' => Link::class, |
|
70 | + ]; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + private static $owns = [ |
|
76 | + 'Image', |
|
77 | + ]; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + private static $table_name = 'SlideImage'; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + private static $default_sort = 'SortOrder'; |
|
88 | + |
|
89 | + /** |
|
90 | + * Adds Publish button to SlideImage record |
|
91 | + * |
|
92 | + * @var bool |
|
93 | + */ |
|
94 | + private static $versioned_gridfield_extensions = true; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + private static $defaults = [ |
|
100 | + 'SlideType' => 'Image', |
|
101 | + ]; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var array |
|
105 | + */ |
|
106 | + private static $summary_fields = [ |
|
107 | + 'Image.CMSThumbnail' => 'Image', |
|
108 | + 'Name' => 'Name', |
|
109 | + ]; |
|
110 | + |
|
111 | + /** |
|
112 | + * @var array |
|
113 | + */ |
|
114 | + private static $searchable_fields = [ |
|
115 | + 'Name', |
|
116 | + 'Headline', |
|
117 | + 'Description', |
|
118 | + ]; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var int |
|
122 | + */ |
|
123 | + private static $image_size_limit = 512000; |
|
124 | + |
|
125 | + /** |
|
126 | + * @var array |
|
127 | + */ |
|
128 | + private static $slide_types = [ |
|
129 | + 'Image', |
|
130 | + 'Video', |
|
131 | + 'Text', |
|
132 | + ]; |
|
133 | + |
|
134 | + /** |
|
135 | + * @param bool $includerelations |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function fieldLabels($includerelations = true) |
|
139 | + { |
|
140 | + $labels = parent::fieldLabels($includerelations); |
|
141 | + |
|
142 | + $labels['Name'] = _t(__CLASS__ . '.NAME', 'Name'); |
|
143 | + $labels['Headline'] = _t(__CLASS__ . '.HEADLINE', 'Headline'); |
|
144 | + $labels['Description'] = _t(__CLASS__ . '.DESCRIPTION', 'Description'); |
|
145 | + $labels['SlideLinkID'] = _t(__CLASS__ . '.PAGE_LINK', "Call to action link"); |
|
146 | + $labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image'); |
|
147 | + $labels['SlideType'] = _t(__CLASS__ . '.SlideType', 'Image or Video'); |
|
148 | + $labels['Video'] = _t(__CLASS__ . '.VideoLabel', 'Video URL'); |
|
149 | + |
|
150 | + return $labels; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @return \SilverStripe\Forms\FieldList |
|
155 | + */ |
|
156 | + public function getCMSFields() |
|
157 | + { |
|
158 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
159 | + $fields->removeByName([ |
|
160 | + 'ShowSlide', |
|
161 | + 'SortOrder', |
|
162 | + 'PageID', |
|
163 | + 'Image', |
|
164 | + 'SlideType', |
|
165 | + 'Video', |
|
166 | + 'VideoID', |
|
167 | + 'SlideLinkID', |
|
168 | + ]); |
|
169 | + |
|
170 | + // Name |
|
171 | + $fields->dataFieldByName('Name') |
|
172 | + ->setDescription( |
|
173 | + _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only') |
|
174 | + ); |
|
175 | + |
|
176 | + // Headline |
|
177 | + $fields->dataFieldByName('Headline') |
|
178 | + ->setDescription( |
|
179 | + _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template') |
|
180 | + ); |
|
181 | + |
|
182 | + // Description |
|
183 | + $fields->dataFieldByName('Description') |
|
184 | + ->setDescription( |
|
185 | + _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template') |
|
186 | + ); |
|
187 | + |
|
188 | + // Page link |
|
189 | + $fields->replaceField( |
|
190 | + 'PageLinkID', |
|
191 | + LinkField::create('SlideLink', $this->fieldLabel('SlideLinkID'), $this) |
|
192 | + ); |
|
193 | + |
|
194 | + // Image |
|
195 | + $image = UploadField::create('Image', $this->fieldLabel('Image')) |
|
196 | + ->setFolderName('Uploads/SlideImages'); |
|
197 | + |
|
198 | + $image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']); |
|
199 | + |
|
200 | + $fields->addFieldToTab( |
|
201 | + 'Root.Main', |
|
202 | + CompositeField::create(FieldList::create( |
|
203 | + DropdownField::create('SlideType', $this->fieldLabel('SlideType')) |
|
204 | + ->setSource($this->getTypeSource()), |
|
205 | + Wrapper::create( |
|
206 | + $image |
|
207 | + )->displayIf('SlideType')->isEqualTo('Image')->orIf('SlideType')->isEqualTo('Video')->end(), |
|
208 | + /*Wrapper::create( |
|
209 | 209 | $videoField = HasOneButtonField::create( |
210 | 210 | 'Video', |
211 | 211 | 'Video', |
212 | 212 | $this |
213 | 213 | ) |
214 | 214 | )->displayIf('SlideType')->isEqualTo('Video')->end()*/ |
215 | - ))->setName('MediaFields'), |
|
216 | - 'Description' |
|
217 | - ); |
|
218 | - }); |
|
219 | - |
|
220 | - $fields = parent::getCMSFields(); |
|
221 | - |
|
222 | - $this->extend('updateSlideImageFields', $fields); |
|
223 | - |
|
224 | - return $fields; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return \SilverStripe\ORM\ValidationResult |
|
229 | - */ |
|
230 | - public function validate() |
|
231 | - { |
|
232 | - $result = parent::validate(); |
|
233 | - |
|
234 | - if (!$this->Name) { |
|
235 | - $result->addError( |
|
236 | - _t(__CLASS__ . '.NAME_REQUIRED', 'A Name is required before you can save') |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - $types = $this->getTypeSource(); |
|
241 | - |
|
242 | - if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) { |
|
243 | - $result->addError( |
|
244 | - _t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save') |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) { |
|
249 | - $result->addError( |
|
250 | - _t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save') |
|
251 | - ); |
|
252 | - } |
|
253 | - |
|
254 | - if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) { |
|
255 | - $result->addError( |
|
256 | - _t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save') |
|
257 | - ); |
|
258 | - } |
|
259 | - |
|
260 | - return $result; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @return array |
|
265 | - */ |
|
266 | - public function providePermissions() |
|
267 | - { |
|
268 | - return [ |
|
269 | - 'Slide_EDIT' => 'Slide Edit', |
|
270 | - 'Slide_DELETE' => 'Slide Delete', |
|
271 | - 'Slide_CREATE' => 'Slide Create', |
|
272 | - ]; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @param null $member |
|
277 | - * @param array $context |
|
278 | - * |
|
279 | - * @return bool|int |
|
280 | - */ |
|
281 | - public function canCreate($member = null, $context = []) |
|
282 | - { |
|
283 | - return Permission::check('Slide_CREATE', 'any', $member); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @param null $member |
|
288 | - * @param array $context |
|
289 | - * |
|
290 | - * @return bool|int |
|
291 | - */ |
|
292 | - public function canEdit($member = null, $context = []) |
|
293 | - { |
|
294 | - return Permission::check('Slide_EDIT', 'any', $member); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * @param null $member |
|
299 | - * @param array $context |
|
300 | - * |
|
301 | - * @return bool|int |
|
302 | - */ |
|
303 | - public function canDelete($member = null, $context = []) |
|
304 | - { |
|
305 | - return Permission::check('Slide_DELETE', 'any', $member); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @param null $member |
|
310 | - * @param array $context |
|
311 | - * |
|
312 | - * @return bool |
|
313 | - */ |
|
314 | - public function canView($member = null, $context = []) |
|
315 | - { |
|
316 | - return true; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public function getTypeSource() |
|
323 | - { |
|
324 | - $types = $this->config()->get('slide_types'); |
|
325 | - asort($types); |
|
326 | - return array_combine($types, $types); |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * @param null $template |
|
331 | - * @param null $customFields |
|
332 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
333 | - */ |
|
334 | - public function renderWith($template = null, $customFields = null) |
|
335 | - { |
|
336 | - if ($template === null) { |
|
337 | - $template = static::class; |
|
338 | - $template = ($this->SlideType) ? $template . "_{$this->SlideType}" : ''; |
|
339 | - } |
|
340 | - |
|
341 | - return parent::renderWith($template); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
346 | - */ |
|
347 | - public function forTemplate() |
|
348 | - { |
|
349 | - return $this->renderWith(); |
|
350 | - } |
|
215 | + ))->setName('MediaFields'), |
|
216 | + 'Description' |
|
217 | + ); |
|
218 | + }); |
|
219 | + |
|
220 | + $fields = parent::getCMSFields(); |
|
221 | + |
|
222 | + $this->extend('updateSlideImageFields', $fields); |
|
223 | + |
|
224 | + return $fields; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return \SilverStripe\ORM\ValidationResult |
|
229 | + */ |
|
230 | + public function validate() |
|
231 | + { |
|
232 | + $result = parent::validate(); |
|
233 | + |
|
234 | + if (!$this->Name) { |
|
235 | + $result->addError( |
|
236 | + _t(__CLASS__ . '.NAME_REQUIRED', 'A Name is required before you can save') |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + $types = $this->getTypeSource(); |
|
241 | + |
|
242 | + if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) { |
|
243 | + $result->addError( |
|
244 | + _t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save') |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) { |
|
249 | + $result->addError( |
|
250 | + _t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save') |
|
251 | + ); |
|
252 | + } |
|
253 | + |
|
254 | + if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) { |
|
255 | + $result->addError( |
|
256 | + _t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save') |
|
257 | + ); |
|
258 | + } |
|
259 | + |
|
260 | + return $result; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @return array |
|
265 | + */ |
|
266 | + public function providePermissions() |
|
267 | + { |
|
268 | + return [ |
|
269 | + 'Slide_EDIT' => 'Slide Edit', |
|
270 | + 'Slide_DELETE' => 'Slide Delete', |
|
271 | + 'Slide_CREATE' => 'Slide Create', |
|
272 | + ]; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @param null $member |
|
277 | + * @param array $context |
|
278 | + * |
|
279 | + * @return bool|int |
|
280 | + */ |
|
281 | + public function canCreate($member = null, $context = []) |
|
282 | + { |
|
283 | + return Permission::check('Slide_CREATE', 'any', $member); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @param null $member |
|
288 | + * @param array $context |
|
289 | + * |
|
290 | + * @return bool|int |
|
291 | + */ |
|
292 | + public function canEdit($member = null, $context = []) |
|
293 | + { |
|
294 | + return Permission::check('Slide_EDIT', 'any', $member); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * @param null $member |
|
299 | + * @param array $context |
|
300 | + * |
|
301 | + * @return bool|int |
|
302 | + */ |
|
303 | + public function canDelete($member = null, $context = []) |
|
304 | + { |
|
305 | + return Permission::check('Slide_DELETE', 'any', $member); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @param null $member |
|
310 | + * @param array $context |
|
311 | + * |
|
312 | + * @return bool |
|
313 | + */ |
|
314 | + public function canView($member = null, $context = []) |
|
315 | + { |
|
316 | + return true; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public function getTypeSource() |
|
323 | + { |
|
324 | + $types = $this->config()->get('slide_types'); |
|
325 | + asort($types); |
|
326 | + return array_combine($types, $types); |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * @param null $template |
|
331 | + * @param null $customFields |
|
332 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
333 | + */ |
|
334 | + public function renderWith($template = null, $customFields = null) |
|
335 | + { |
|
336 | + if ($template === null) { |
|
337 | + $template = static::class; |
|
338 | + $template = ($this->SlideType) ? $template . "_{$this->SlideType}" : ''; |
|
339 | + } |
|
340 | + |
|
341 | + return parent::renderWith($template); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
346 | + */ |
|
347 | + public function forTemplate() |
|
348 | + { |
|
349 | + return $this->renderWith(); |
|
350 | + } |
|
351 | 351 | } |
@@ -37,189 +37,189 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class FlexSlider extends DataExtension |
39 | 39 | { |
40 | - use Configurable; |
|
40 | + use Configurable; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $db = [ |
|
46 | - 'Animation' => "Enum('slide, fade', 'slide')", |
|
47 | - 'Loop' => 'Boolean', |
|
48 | - 'Animate' => 'Boolean', |
|
49 | - 'ThumbnailNav' => 'Boolean', |
|
50 | - 'SliderControlNav' => 'Boolean', |
|
51 | - 'SliderDirectionNav' => 'Boolean', |
|
52 | - 'CarouselControlNav' => 'Boolean', |
|
53 | - 'CarouselDirectionNav' => 'Boolean', |
|
54 | - 'CarouselThumbnailCt' => 'Int', |
|
55 | - 'FlexSliderSpeed' => 'Double', |
|
56 | - ]; |
|
42 | + /** |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $db = [ |
|
46 | + 'Animation' => "Enum('slide, fade', 'slide')", |
|
47 | + 'Loop' => 'Boolean', |
|
48 | + 'Animate' => 'Boolean', |
|
49 | + 'ThumbnailNav' => 'Boolean', |
|
50 | + 'SliderControlNav' => 'Boolean', |
|
51 | + 'SliderDirectionNav' => 'Boolean', |
|
52 | + 'CarouselControlNav' => 'Boolean', |
|
53 | + 'CarouselDirectionNav' => 'Boolean', |
|
54 | + 'CarouselThumbnailCt' => 'Int', |
|
55 | + 'FlexSliderSpeed' => 'Double', |
|
56 | + ]; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - private static $has_many = [ |
|
62 | - 'Slides' => SlideImage::class, |
|
63 | - ]; |
|
58 | + /** |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + private static $has_many = [ |
|
62 | + 'Slides' => SlideImage::class, |
|
63 | + ]; |
|
64 | 64 | |
65 | - /** |
|
66 | - * |
|
67 | - */ |
|
68 | - public function populateDefaults() |
|
69 | - { |
|
70 | - $this->owner->Loop = 1; |
|
71 | - $this->owner->Animate = 1; |
|
72 | - $this->owner->SliderControlNav = 0; |
|
73 | - $this->owner->SliderDirectionNav = 1; |
|
74 | - $this->owner->CarouselControlNav = 0; |
|
75 | - $this->owner->CarouselDirectionNav = 1; |
|
76 | - $this->owner->CarouselThumbnailCt = 6; |
|
77 | - $this->owner->FlexSliderSpeed = $this->getDefaultSpeed(); |
|
65 | + /** |
|
66 | + * |
|
67 | + */ |
|
68 | + public function populateDefaults() |
|
69 | + { |
|
70 | + $this->owner->Loop = 1; |
|
71 | + $this->owner->Animate = 1; |
|
72 | + $this->owner->SliderControlNav = 0; |
|
73 | + $this->owner->SliderDirectionNav = 1; |
|
74 | + $this->owner->CarouselControlNav = 0; |
|
75 | + $this->owner->CarouselDirectionNav = 1; |
|
76 | + $this->owner->CarouselThumbnailCt = 6; |
|
77 | + $this->owner->FlexSliderSpeed = $this->getDefaultSpeed(); |
|
78 | 78 | |
79 | - return parent::populateDefaults(); |
|
80 | - } |
|
79 | + return parent::populateDefaults(); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param FieldList $fields |
|
84 | - */ |
|
85 | - public function updateCMSFields(FieldList $fields) |
|
86 | - { |
|
87 | - $fields->removeByName([ |
|
88 | - 'Animation', |
|
89 | - 'Loop', |
|
90 | - 'Animate', |
|
91 | - 'ThumbnailNav', |
|
92 | - 'SliderControlNav', |
|
93 | - 'SliderDirectionNav', |
|
94 | - 'CarouselControlNav', |
|
95 | - 'CarouselDirectionNav', |
|
96 | - 'CarouselThumbnailCt', |
|
97 | - 'FlexSliderSpeed', |
|
98 | - 'Slides', |
|
99 | - ]); |
|
82 | + /** |
|
83 | + * @param FieldList $fields |
|
84 | + */ |
|
85 | + public function updateCMSFields(FieldList $fields) |
|
86 | + { |
|
87 | + $fields->removeByName([ |
|
88 | + 'Animation', |
|
89 | + 'Loop', |
|
90 | + 'Animate', |
|
91 | + 'ThumbnailNav', |
|
92 | + 'SliderControlNav', |
|
93 | + 'SliderDirectionNav', |
|
94 | + 'CarouselControlNav', |
|
95 | + 'CarouselDirectionNav', |
|
96 | + 'CarouselThumbnailCt', |
|
97 | + 'FlexSliderSpeed', |
|
98 | + 'Slides', |
|
99 | + ]); |
|
100 | 100 | |
101 | - // Slides |
|
102 | - if ($this->owner->ID) { |
|
103 | - $config = GridFieldConfig_RecordEditor::create(); |
|
104 | - $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
105 | - $config->removeComponentsByType([ |
|
106 | - GridFieldAddExistingAutocompleter::class, |
|
107 | - GridFieldDeleteAction::class, |
|
108 | - ]); |
|
109 | - $SlidesField = GridField::create( |
|
110 | - 'Slides', |
|
111 | - _t(__CLASS__ . '.SLIDES', 'Slides'), |
|
112 | - $this->owner->Slides()->sort('SortOrder'), |
|
113 | - $config |
|
114 | - ); |
|
101 | + // Slides |
|
102 | + if ($this->owner->ID) { |
|
103 | + $config = GridFieldConfig_RecordEditor::create(); |
|
104 | + $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
105 | + $config->removeComponentsByType([ |
|
106 | + GridFieldAddExistingAutocompleter::class, |
|
107 | + GridFieldDeleteAction::class, |
|
108 | + ]); |
|
109 | + $SlidesField = GridField::create( |
|
110 | + 'Slides', |
|
111 | + _t(__CLASS__ . '.SLIDES', 'Slides'), |
|
112 | + $this->owner->Slides()->sort('SortOrder'), |
|
113 | + $config |
|
114 | + ); |
|
115 | 115 | |
116 | - $slideTitle = $this->owner->slide_tab_title ?: _t(__CLASS__ . '.SLIDES', 'Slides'); |
|
116 | + $slideTitle = $this->owner->slide_tab_title ?: _t(__CLASS__ . '.SLIDES', 'Slides'); |
|
117 | 117 | |
118 | - $animations = []; |
|
119 | - $animationOptions = $this->owner->dbObject('Animation')->getEnum(); |
|
120 | - foreach ($animationOptions as $value) { |
|
121 | - $animations[$value] = _t(__CLASS__ . ".$value", $value); |
|
122 | - } |
|
118 | + $animations = []; |
|
119 | + $animationOptions = $this->owner->dbObject('Animation')->getEnum(); |
|
120 | + foreach ($animationOptions as $value) { |
|
121 | + $animations[$value] = _t(__CLASS__ . ".$value", $value); |
|
122 | + } |
|
123 | 123 | |
124 | - $fields->addFieldsToTab("Root.{$slideTitle}", [ |
|
125 | - $SlidesField, |
|
126 | - ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [ |
|
127 | - DropdownField::create( |
|
128 | - 'Animation', |
|
129 | - _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'), |
|
130 | - $animations |
|
131 | - ), |
|
132 | - CheckboxField::create( |
|
133 | - 'Animate', |
|
134 | - _t(__CLASS__ . '.ANIMATE', 'Animate automatically') |
|
135 | - ), |
|
136 | - CheckboxField::create( |
|
137 | - 'Loop', |
|
138 | - _t(__CLASS__ . '.LOOP', 'Loop the carousel') |
|
139 | - ), |
|
140 | - CheckboxField::create( |
|
141 | - 'SliderControlNav', |
|
142 | - _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav') |
|
143 | - ), |
|
144 | - CheckboxField::create( |
|
145 | - 'SliderDirectionNav', |
|
146 | - _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav') |
|
147 | - ), |
|
148 | - CheckboxField::create( |
|
149 | - 'ThumbnailNav', |
|
150 | - _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation') |
|
151 | - ), |
|
152 | - //DisplayLogicWrapper::create( |
|
153 | - CheckboxField::create( |
|
154 | - 'CarouselControlNav', |
|
155 | - _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav') |
|
156 | - ), |
|
157 | - CheckboxField::create( |
|
158 | - 'CarouselDirectionNav', |
|
159 | - _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav') |
|
160 | - ), |
|
161 | - NumericField::create( |
|
162 | - 'CarouselThumbnailCt', |
|
163 | - _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails') |
|
164 | - ), |
|
165 | - NumericField::create( |
|
166 | - 'FlexSliderSpeed', |
|
167 | - _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed') |
|
168 | - ) |
|
169 | - ->setDescription('In Seconds') |
|
170 | - ->setScale(2), |
|
171 | - ]), |
|
172 | - ]); |
|
173 | - } |
|
174 | - } |
|
124 | + $fields->addFieldsToTab("Root.{$slideTitle}", [ |
|
125 | + $SlidesField, |
|
126 | + ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [ |
|
127 | + DropdownField::create( |
|
128 | + 'Animation', |
|
129 | + _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'), |
|
130 | + $animations |
|
131 | + ), |
|
132 | + CheckboxField::create( |
|
133 | + 'Animate', |
|
134 | + _t(__CLASS__ . '.ANIMATE', 'Animate automatically') |
|
135 | + ), |
|
136 | + CheckboxField::create( |
|
137 | + 'Loop', |
|
138 | + _t(__CLASS__ . '.LOOP', 'Loop the carousel') |
|
139 | + ), |
|
140 | + CheckboxField::create( |
|
141 | + 'SliderControlNav', |
|
142 | + _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav') |
|
143 | + ), |
|
144 | + CheckboxField::create( |
|
145 | + 'SliderDirectionNav', |
|
146 | + _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav') |
|
147 | + ), |
|
148 | + CheckboxField::create( |
|
149 | + 'ThumbnailNav', |
|
150 | + _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation') |
|
151 | + ), |
|
152 | + //DisplayLogicWrapper::create( |
|
153 | + CheckboxField::create( |
|
154 | + 'CarouselControlNav', |
|
155 | + _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav') |
|
156 | + ), |
|
157 | + CheckboxField::create( |
|
158 | + 'CarouselDirectionNav', |
|
159 | + _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav') |
|
160 | + ), |
|
161 | + NumericField::create( |
|
162 | + 'CarouselThumbnailCt', |
|
163 | + _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails') |
|
164 | + ), |
|
165 | + NumericField::create( |
|
166 | + 'FlexSliderSpeed', |
|
167 | + _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed') |
|
168 | + ) |
|
169 | + ->setDescription('In Seconds') |
|
170 | + ->setScale(2), |
|
171 | + ]), |
|
172 | + ]); |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @return mixed |
|
178 | - */ |
|
179 | - public function getSlideShow() |
|
180 | - { |
|
181 | - $owner = $this->owner; |
|
176 | + /** |
|
177 | + * @return mixed |
|
178 | + */ |
|
179 | + public function getSlideShow() |
|
180 | + { |
|
181 | + $owner = $this->owner; |
|
182 | 182 | |
183 | - if (!($owner instanceof SiteTree)) { |
|
184 | - $this->getCustomScript(); |
|
185 | - } |
|
183 | + if (!($owner instanceof SiteTree)) { |
|
184 | + $this->getCustomScript(); |
|
185 | + } |
|
186 | 186 | |
187 | - return $this->owner->Slides()->sort('SortOrder'); |
|
188 | - } |
|
187 | + return $this->owner->Slides()->sort('SortOrder'); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * add requirements to PageController init() |
|
192 | - */ |
|
193 | - public function contentcontrollerInit() |
|
194 | - { |
|
195 | - // only call custom script if page has Slides and DataExtension |
|
196 | - if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) { |
|
197 | - if ($this->owner->getSlideShow()->exists()) { |
|
198 | - $this->getCustomScript(); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
190 | + /** |
|
191 | + * add requirements to PageController init() |
|
192 | + */ |
|
193 | + public function contentcontrollerInit() |
|
194 | + { |
|
195 | + // only call custom script if page has Slides and DataExtension |
|
196 | + if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) { |
|
197 | + if ($this->owner->getSlideShow()->exists()) { |
|
198 | + $this->getCustomScript(); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * |
|
205 | - */ |
|
206 | - public function getCustomScript() |
|
207 | - { |
|
208 | - // Flexslider options |
|
209 | - $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : ''; |
|
203 | + /** |
|
204 | + * |
|
205 | + */ |
|
206 | + public function getCustomScript() |
|
207 | + { |
|
208 | + // Flexslider options |
|
209 | + $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : ''; |
|
210 | 210 | |
211 | - $before = $this->owner->hasMethod('flexSliderBeforeAction') |
|
212 | - ? $this->owner->flexSliderBeforeAction() |
|
213 | - : 'function(){}'; |
|
211 | + $before = $this->owner->hasMethod('flexSliderBeforeAction') |
|
212 | + ? $this->owner->flexSliderBeforeAction() |
|
213 | + : 'function(){}'; |
|
214 | 214 | |
215 | - $after = $this->owner->hasMethod('flexSliderAfterAction') |
|
216 | - ? $this->owner->flexSliderAfterAction() |
|
217 | - : 'function(){}'; |
|
215 | + $after = $this->owner->hasMethod('flexSliderAfterAction') |
|
216 | + ? $this->owner->flexSliderAfterAction() |
|
217 | + : 'function(){}'; |
|
218 | 218 | |
219 | - $speed = $this->getSlideshowSpeed(); |
|
219 | + $speed = $this->getSlideshowSpeed(); |
|
220 | 220 | |
221 | - Requirements::customScript( |
|
222 | - "(function($) { |
|
221 | + Requirements::customScript( |
|
222 | + "(function($) { |
|
223 | 223 | $(document).ready(function(){ |
224 | 224 | jQuery('.flexslider').each(function(index){ |
225 | 225 | |
@@ -265,39 +265,39 @@ discard block |
||
265 | 265 | }) |
266 | 266 | }); |
267 | 267 | }(jQuery));' |
268 | - ); |
|
269 | - } |
|
268 | + ); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @return int |
|
273 | - */ |
|
274 | - public function getSlideshowSpeed() |
|
275 | - { |
|
276 | - $speed = $this->owner->FlexSliderSpeed > 0 |
|
277 | - ? $this->owner->FlexSliderSpeed |
|
278 | - : $this->getDefaultSpeed(); |
|
271 | + /** |
|
272 | + * @return int |
|
273 | + */ |
|
274 | + public function getSlideshowSpeed() |
|
275 | + { |
|
276 | + $speed = $this->owner->FlexSliderSpeed > 0 |
|
277 | + ? $this->owner->FlexSliderSpeed |
|
278 | + : $this->getDefaultSpeed(); |
|
279 | 279 | |
280 | - return $speed * 1000; |
|
281 | - } |
|
280 | + return $speed * 1000; |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * @return mixed |
|
285 | - */ |
|
286 | - protected function getDefaultSpeed() |
|
287 | - { |
|
288 | - return $this->owner->config()->get('flex_slider_speed') |
|
289 | - ?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed'); |
|
290 | - } |
|
283 | + /** |
|
284 | + * @return mixed |
|
285 | + */ |
|
286 | + protected function getDefaultSpeed() |
|
287 | + { |
|
288 | + return $this->owner->config()->get('flex_slider_speed') |
|
289 | + ?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed'); |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * |
|
294 | - */ |
|
295 | - public function onBeforeWrite() |
|
296 | - { |
|
297 | - parent::onBeforeWrite(); |
|
292 | + /** |
|
293 | + * |
|
294 | + */ |
|
295 | + public function onBeforeWrite() |
|
296 | + { |
|
297 | + parent::onBeforeWrite(); |
|
298 | 298 | |
299 | - if (!$this->owner->CarouselThumbnailCt) { |
|
300 | - $this->owner->CarouselThumbnailCt = 6; |
|
301 | - } |
|
302 | - } |
|
299 | + if (!$this->owner->CarouselThumbnailCt) { |
|
300 | + $this->owner->CarouselThumbnailCt = 6; |
|
301 | + } |
|
302 | + } |
|
303 | 303 | } |