Passed
Pull Request — 4 (#212)
by
unknown
02:34
created
src/ORM/FlexSlider.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -37,205 +37,205 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class FlexSlider extends DataExtension
39 39
 {
40
-    use Configurable;
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
-    ];
57
-
58
-    /**
59
-     * @var array
60
-     */
61
-    private static $has_many = [
62
-        'Slides' => SlideImage::class,
63
-    ];
64
-
65
-    /**
66
-     * @var bool
67
-     */
68
-    private static $jquery_enabled = true;
69
-
70
-    /**
71
-     * @var bool
72
-     */
73
-    private static $flexslider_enabled = true;
74
-
75
-    /**
76
-     *
77
-     */
78
-    public function populateDefaults()
79
-    {
80
-        $this->owner->Loop = 1;
81
-        $this->owner->Animate = 1;
82
-        $this->owner->SliderControlNav = 0;
83
-        $this->owner->SliderDirectionNav = 1;
84
-        $this->owner->CarouselControlNav = 0;
85
-        $this->owner->CarouselDirectionNav = 1;
86
-        $this->owner->CarouselThumbnailCt = 6;
87
-        $this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
88
-
89
-        return parent::populateDefaults();
90
-    }
91
-
92
-    /**
93
-     * @param FieldList $fields
94
-     */
95
-    public function updateCMSFields(FieldList $fields)
96
-    {
97
-        $fields->removeByName([
98
-            'Animation',
99
-            'Loop',
100
-            'Animate',
101
-            'ThumbnailNav',
102
-            'SliderControlNav',
103
-            'SliderDirectionNav',
104
-            'CarouselControlNav',
105
-            'CarouselDirectionNav',
106
-            'CarouselThumbnailCt',
107
-            'FlexSliderSpeed',
108
-            'Slides',
109
-        ]);
110
-
111
-        // Slides
112
-        if ($this->owner->ID) {
113
-            $config = GridFieldConfig_RecordEditor::create();
114
-            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
115
-            $config->removeComponentsByType([
116
-                GridFieldAddExistingAutocompleter::class,
117
-                GridFieldDeleteAction::class,
118
-            ]);
119
-            $SlidesField = GridField::create(
120
-                'Slides',
121
-                _t(__CLASS__ . '.SLIDES', 'Slides'),
122
-                $this->owner->Slides()->sort('SortOrder'),
123
-                $config
124
-            );
125
-
126
-            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
127
-
128
-            $animations = [];
129
-            $animationOptions = $this->owner->dbObject('Animation')->getEnum();
130
-            foreach ($animationOptions as $value) {
131
-                $animations[$value] = _t(__CLASS__ . ".$value", $value);
132
-            }
133
-
134
-            $fields->addFieldsToTab("Root.{$slideTitle}", [
135
-                $SlidesField,
136
-                ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
137
-                    DropdownField::create(
138
-                        'Animation',
139
-                        _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
140
-                        $animations
141
-                    ),
142
-                    CheckboxField::create(
143
-                        'Animate',
144
-                        _t(__CLASS__ . '.ANIMATE', 'Animate automatically')
145
-                    ),
146
-                    CheckboxField::create(
147
-                        'Loop',
148
-                        _t(__CLASS__ . '.LOOP', 'Loop the carousel')
149
-                    ),
150
-                    CheckboxField::create(
151
-                        'SliderControlNav',
152
-                        _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
153
-                    ),
154
-                    CheckboxField::create(
155
-                        'SliderDirectionNav',
156
-                        _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
157
-                    ),
158
-                    CheckboxField::create(
159
-                        'ThumbnailNav',
160
-                        _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
161
-                    ),
162
-                    //DisplayLogicWrapper::create(
163
-                    CheckboxField::create(
164
-                        'CarouselControlNav',
165
-                        _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
166
-                    ),
167
-                    CheckboxField::create(
168
-                        'CarouselDirectionNav',
169
-                        _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
170
-                    ),
171
-                    NumericField::create(
172
-                        'CarouselThumbnailCt',
173
-                        _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
174
-                    ),
175
-                    NumericField::create(
176
-                        'FlexSliderSpeed',
177
-                        _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
178
-                    )
179
-                        ->setDescription('In Seconds')
180
-                        ->setScale(2),
181
-                ]),
182
-            ]);
183
-        }
184
-    }
185
-
186
-    /**
187
-     * @return mixed
188
-     */
189
-    public function getSlideShow()
190
-    {
191
-        $owner = $this->owner;
192
-
193
-        if (!($owner instanceof SiteTree)) {
194
-            $this->getCustomScript();
195
-        }
196
-
197
-        return $this->owner->Slides()->sort('SortOrder');
198
-    }
199
-
200
-    /**
201
-     * add requirements to PageController init()
202
-     */
203
-    public function contentcontrollerInit()
204
-    {
205
-        // only call custom script if page has Slides and DataExtension
206
-        if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
207
-            if ($this->owner->config()->get('jquery_enabled')) {
208
-                Requirements::javascript('//code.jquery.com/jquery-3.6.1.min.js');
209
-            }
210
-
211
-            if ($this->owner->getSlideShow()->exists() && $this->owner->config()->get('flexslider_enabled')) {
212
-                Requirements::javascript('dynamic/flexslider:thirdparty/flexslider/jquery.flexslider-min.js');
213
-            }
214
-
215
-            $this->getCustomScript();
216
-        }
217
-    }
218
-
219
-    /**
220
-     *
221
-     */
222
-    public function getCustomScript()
223
-    {
224
-        // Flexslider options
225
-        $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
226
-
227
-        $before = $this->owner->hasMethod('flexSliderBeforeAction')
228
-            ? $this->owner->flexSliderBeforeAction()
229
-            : 'function(){}';
230
-
231
-        $after = $this->owner->hasMethod('flexSliderAfterAction')
232
-            ? $this->owner->flexSliderAfterAction()
233
-            : 'function(){}';
234
-
235
-        $speed = $this->getSlideshowSpeed();
236
-
237
-        Requirements::customScript(
238
-            "(function($) {
40
+	use Configurable;
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
+	];
57
+
58
+	/**
59
+	 * @var array
60
+	 */
61
+	private static $has_many = [
62
+		'Slides' => SlideImage::class,
63
+	];
64
+
65
+	/**
66
+	 * @var bool
67
+	 */
68
+	private static $jquery_enabled = true;
69
+
70
+	/**
71
+	 * @var bool
72
+	 */
73
+	private static $flexslider_enabled = true;
74
+
75
+	/**
76
+	 *
77
+	 */
78
+	public function populateDefaults()
79
+	{
80
+		$this->owner->Loop = 1;
81
+		$this->owner->Animate = 1;
82
+		$this->owner->SliderControlNav = 0;
83
+		$this->owner->SliderDirectionNav = 1;
84
+		$this->owner->CarouselControlNav = 0;
85
+		$this->owner->CarouselDirectionNav = 1;
86
+		$this->owner->CarouselThumbnailCt = 6;
87
+		$this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
88
+
89
+		return parent::populateDefaults();
90
+	}
91
+
92
+	/**
93
+	 * @param FieldList $fields
94
+	 */
95
+	public function updateCMSFields(FieldList $fields)
96
+	{
97
+		$fields->removeByName([
98
+			'Animation',
99
+			'Loop',
100
+			'Animate',
101
+			'ThumbnailNav',
102
+			'SliderControlNav',
103
+			'SliderDirectionNav',
104
+			'CarouselControlNav',
105
+			'CarouselDirectionNav',
106
+			'CarouselThumbnailCt',
107
+			'FlexSliderSpeed',
108
+			'Slides',
109
+		]);
110
+
111
+		// Slides
112
+		if ($this->owner->ID) {
113
+			$config = GridFieldConfig_RecordEditor::create();
114
+			$config->addComponent(new GridFieldOrderableRows('SortOrder'));
115
+			$config->removeComponentsByType([
116
+				GridFieldAddExistingAutocompleter::class,
117
+				GridFieldDeleteAction::class,
118
+			]);
119
+			$SlidesField = GridField::create(
120
+				'Slides',
121
+				_t(__CLASS__ . '.SLIDES', 'Slides'),
122
+				$this->owner->Slides()->sort('SortOrder'),
123
+				$config
124
+			);
125
+
126
+			$slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
127
+
128
+			$animations = [];
129
+			$animationOptions = $this->owner->dbObject('Animation')->getEnum();
130
+			foreach ($animationOptions as $value) {
131
+				$animations[$value] = _t(__CLASS__ . ".$value", $value);
132
+			}
133
+
134
+			$fields->addFieldsToTab("Root.{$slideTitle}", [
135
+				$SlidesField,
136
+				ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
137
+					DropdownField::create(
138
+						'Animation',
139
+						_t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
140
+						$animations
141
+					),
142
+					CheckboxField::create(
143
+						'Animate',
144
+						_t(__CLASS__ . '.ANIMATE', 'Animate automatically')
145
+					),
146
+					CheckboxField::create(
147
+						'Loop',
148
+						_t(__CLASS__ . '.LOOP', 'Loop the carousel')
149
+					),
150
+					CheckboxField::create(
151
+						'SliderControlNav',
152
+						_t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
153
+					),
154
+					CheckboxField::create(
155
+						'SliderDirectionNav',
156
+						_t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
157
+					),
158
+					CheckboxField::create(
159
+						'ThumbnailNav',
160
+						_t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
161
+					),
162
+					//DisplayLogicWrapper::create(
163
+					CheckboxField::create(
164
+						'CarouselControlNav',
165
+						_t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
166
+					),
167
+					CheckboxField::create(
168
+						'CarouselDirectionNav',
169
+						_t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
170
+					),
171
+					NumericField::create(
172
+						'CarouselThumbnailCt',
173
+						_t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
174
+					),
175
+					NumericField::create(
176
+						'FlexSliderSpeed',
177
+						_t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
178
+					)
179
+						->setDescription('In Seconds')
180
+						->setScale(2),
181
+				]),
182
+			]);
183
+		}
184
+	}
185
+
186
+	/**
187
+	 * @return mixed
188
+	 */
189
+	public function getSlideShow()
190
+	{
191
+		$owner = $this->owner;
192
+
193
+		if (!($owner instanceof SiteTree)) {
194
+			$this->getCustomScript();
195
+		}
196
+
197
+		return $this->owner->Slides()->sort('SortOrder');
198
+	}
199
+
200
+	/**
201
+	 * add requirements to PageController init()
202
+	 */
203
+	public function contentcontrollerInit()
204
+	{
205
+		// only call custom script if page has Slides and DataExtension
206
+		if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
207
+			if ($this->owner->config()->get('jquery_enabled')) {
208
+				Requirements::javascript('//code.jquery.com/jquery-3.6.1.min.js');
209
+			}
210
+
211
+			if ($this->owner->getSlideShow()->exists() && $this->owner->config()->get('flexslider_enabled')) {
212
+				Requirements::javascript('dynamic/flexslider:thirdparty/flexslider/jquery.flexslider-min.js');
213
+			}
214
+
215
+			$this->getCustomScript();
216
+		}
217
+	}
218
+
219
+	/**
220
+	 *
221
+	 */
222
+	public function getCustomScript()
223
+	{
224
+		// Flexslider options
225
+		$sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
226
+
227
+		$before = $this->owner->hasMethod('flexSliderBeforeAction')
228
+			? $this->owner->flexSliderBeforeAction()
229
+			: 'function(){}';
230
+
231
+		$after = $this->owner->hasMethod('flexSliderAfterAction')
232
+			? $this->owner->flexSliderAfterAction()
233
+			: 'function(){}';
234
+
235
+		$speed = $this->getSlideshowSpeed();
236
+
237
+		Requirements::customScript(
238
+			"(function($) {
239 239
                 $(document).ready(function(){
240 240
                     jQuery('.flexslider').each(function(index){
241 241
 
@@ -281,39 +281,39 @@  discard block
 block discarded – undo
281 281
                     })
282 282
                 });
283 283
             }(jQuery));'
284
-        );
285
-    }
286
-
287
-    /**
288
-     * @return int
289
-     */
290
-    public function getSlideshowSpeed()
291
-    {
292
-        $speed = $this->owner->FlexSliderSpeed > 0
293
-            ? $this->owner->FlexSliderSpeed
294
-            : $this->getDefaultSpeed();
295
-
296
-        return $speed * 1000;
297
-    }
298
-
299
-    /**
300
-     * @return mixed
301
-     */
302
-    protected function getDefaultSpeed()
303
-    {
304
-        return $this->owner->config()->get('flex_slider_speed')
305
-            ?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
306
-    }
307
-
308
-    /**
309
-     *
310
-     */
311
-    public function onBeforeWrite()
312
-    {
313
-        parent::onBeforeWrite();
314
-
315
-        if (!$this->owner->CarouselThumbnailCt) {
316
-            $this->owner->CarouselThumbnailCt = 6;
317
-        }
318
-    }
284
+		);
285
+	}
286
+
287
+	/**
288
+	 * @return int
289
+	 */
290
+	public function getSlideshowSpeed()
291
+	{
292
+		$speed = $this->owner->FlexSliderSpeed > 0
293
+			? $this->owner->FlexSliderSpeed
294
+			: $this->getDefaultSpeed();
295
+
296
+		return $speed * 1000;
297
+	}
298
+
299
+	/**
300
+	 * @return mixed
301
+	 */
302
+	protected function getDefaultSpeed()
303
+	{
304
+		return $this->owner->config()->get('flex_slider_speed')
305
+			?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
306
+	}
307
+
308
+	/**
309
+	 *
310
+	 */
311
+	public function onBeforeWrite()
312
+	{
313
+		parent::onBeforeWrite();
314
+
315
+		if (!$this->owner->CarouselThumbnailCt) {
316
+			$this->owner->CarouselThumbnailCt = 6;
317
+		}
318
+	}
319 319
 }
Please login to merge, or discard this patch.