Passed
Pull Request — 4.1 (#212)
by
unknown
03:54
created
tests/SlideImageTest.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -20,197 +20,197 @@
 block discarded – undo
20 20
  */
21 21
 class SlideImageTest extends SapphireTest
22 22
 {
23
-    /**
24
-     * @var string
25
-     */
26
-    protected static $fixture_file = 'fixtures.yml';
27
-
28
-    /**
29
-     *
30
-     */
31
-    public function testGetCMSFields()
32
-    {
33
-        $object = SlideImage::singleton();
34
-        $fields = $object->getCMSFields();
35
-
36
-        $this->assertInstanceOf(FieldList::class, $fields);
37
-        $this->assertInstanceOf(TextField::class, $fields->dataFieldByName('Name'));
38
-        $this->assertInstanceOf(UploadField::class, $fields->dataFieldByName('Image'));
39
-        $this->assertInstanceOf(EmbeddedObjectField::class, $fields->dataFieldByName('Video'));
40
-        $this->assertInstanceOf(TextareaField::class, $fields->dataFieldByName('Description'));
41
-    }
42
-
43
-    /**
44
-     * @throws ValidationException
45
-     */
46
-    public function testValidateName()
47
-    {
48
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
49
-        $object->Name = '';
50
-        $object->ImageID = 1;
51
-        $this->setExpectedException(ValidationException::class);
52
-        $object->write();
53
-
54
-        $object->Name = 'Foo';
55
-        $this->assertGreaterThan(0, $object->write());
56
-    }
57
-
58
-    /**
59
-     * @throws ValidationException
60
-     */
61
-    public function testValidateImage()
62
-    {
63
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
64
-        $object->ImageID = null;
65
-        $this->setExpectedException(ValidationException::class);
66
-        $object->write();
67
-
68
-        $base->ImageID = 1;
69
-        $this->assertGreaterThan(0, $object->write());
70
-    }
71
-
72
-    /**
73
-     * @throws ValidationException
74
-     */
75
-    public function testValidateVideo()
76
-    {
77
-        $object = $this->objFromFixture(SlideImage::class, 'slide2');
78
-        $object->VideoID = null;
79
-        $this->setExpectedException(ValidationException::class);
80
-        $object->write();
81
-
82
-        $object->VideoID = 1;
83
-        $this->assertGreaterThan(0, $object->write());
84
-    }
85
-
86
-    /**
87
-     * @throws ValidationException
88
-     */
89
-    public function testValidateText()
90
-    {
91
-        $object = $this->objFromFixture(SlideImage::class, 'slide3');
92
-        $description = $object->Description;
93
-
94
-        $object->Description = null;
95
-        $this->setExpectedException(ValidationException::class);
96
-        $object->write();
97
-
98
-        $object->Description = $description;
99
-        $this->assertGreaterThan(0, $object->write());
100
-    }
101
-
102
-    /**
103
-     *
104
-     */
105
-    public function testProvidePermissions()
106
-    {
107
-        $object = SlideImage::singleton();
108
-
109
-        $expected = [
110
-            'Slide_EDIT' => 'Slide Edit',
111
-            'Slide_DELETE' => 'Slide Delete',
112
-            'Slide_CREATE' => 'Slide Create',
113
-        ];
114
-
115
-        $this->assertEquals($expected, $object->providePermissions());
116
-    }
117
-
118
-    /**
119
-     *
120
-     */
121
-    public function testCanCreate()
122
-    {
123
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
124
-        $admin = $this->objFromFixture(Member::class, 'admin');
125
-        $this->assertTrue($object->canCreate($admin));
126
-
127
-        $author = $this->objFromFixture(Member::class, 'author');
128
-        $this->assertTrue($object->canCreate($author));
129
-
130
-        $member = $this->objFromFixture(Member::class, 'default');
131
-        $this->assertFalse($object->canCreate($member));
132
-    }
133
-
134
-    /**
135
-     *
136
-     */
137
-    public function testCanEdit()
138
-    {
139
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
140
-        $admin = $this->objFromFixture(Member::class, 'admin');
141
-        $this->assertTrue($object->canEdit($admin));
142
-
143
-        $author = $this->objFromFixture(Member::class, 'author');
144
-        $this->assertTrue($object->canEdit($author));
145
-
146
-        $member = $this->objFromFixture(Member::class, 'default');
147
-        $this->assertFalse($object->canEdit($member));
148
-    }
149
-
150
-    /**
151
-     *
152
-     */
153
-    public function testCanDelete()
154
-    {
155
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
156
-        $admin = $this->objFromFixture(Member::class, 'admin');
157
-        $this->assertTrue($object->canDelete($admin));
158
-
159
-        $author = $this->objFromFixture(Member::class, 'author');
160
-        $this->assertTrue($object->canDelete($author));
161
-
162
-        $member = $this->objFromFixture(Member::class, 'default');
163
-        $this->assertFalse($object->canDelete($member));
164
-    }
165
-
166
-    /**
167
-     *
168
-     */
169
-    public function testCanView()
170
-    {
171
-        $object = $this->objFromFixture(SlideImage::class, 'slide1');
172
-        $admin = $this->objFromFixture(Member::class, 'admin');
173
-        $this->assertTrue($object->canView($admin));
174
-
175
-        $author = $this->objFromFixture(Member::class, 'author');
176
-        $this->assertTrue($object->canView($author));
177
-
178
-        $member = $this->objFromFixture(Member::class, 'default');
179
-        $this->assertTrue($object->canView($member));
180
-    }
181
-
182
-    /**
183
-     *
184
-     */
185
-    public function testImageSizeLimit()
186
-    {
187
-        $default = 512000;
188
-        $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $default);
189
-
190
-        $new = 1024000;
191
-        Config::modify()->update(SlideImage::class, 'image_size_limit', $new);
192
-        $this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $new);
193
-    }
194
-
195
-    /**
196
-     *
197
-     */
198
-    public function testRenderWith()
199
-    {
200
-        $this->markTestSkipped("Todo SlideImageText::testRenderWith()");
201
-        //$slide = SlideImage::singleton();
202
-
203
-        //$this->assertInstanceOf(DBHTMLText::class, $slide->renderWith());
204
-    }
205
-
206
-    /**
207
-     *
208
-     */
209
-    public function testForTemplate()
210
-    {
211
-        $this->markTestSkipped("Todo SlideImageText::testForTemplate()");
212
-        //$slide = SlideImage::singleton();
213
-
214
-        //$this->assertInstanceOf(DBHTMLText::class, $slide->forTemplate());
215
-    }
23
+	/**
24
+	 * @var string
25
+	 */
26
+	protected static $fixture_file = 'fixtures.yml';
27
+
28
+	/**
29
+	 *
30
+	 */
31
+	public function testGetCMSFields()
32
+	{
33
+		$object = SlideImage::singleton();
34
+		$fields = $object->getCMSFields();
35
+
36
+		$this->assertInstanceOf(FieldList::class, $fields);
37
+		$this->assertInstanceOf(TextField::class, $fields->dataFieldByName('Name'));
38
+		$this->assertInstanceOf(UploadField::class, $fields->dataFieldByName('Image'));
39
+		$this->assertInstanceOf(EmbeddedObjectField::class, $fields->dataFieldByName('Video'));
40
+		$this->assertInstanceOf(TextareaField::class, $fields->dataFieldByName('Description'));
41
+	}
42
+
43
+	/**
44
+	 * @throws ValidationException
45
+	 */
46
+	public function testValidateName()
47
+	{
48
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
49
+		$object->Name = '';
50
+		$object->ImageID = 1;
51
+		$this->setExpectedException(ValidationException::class);
52
+		$object->write();
53
+
54
+		$object->Name = 'Foo';
55
+		$this->assertGreaterThan(0, $object->write());
56
+	}
57
+
58
+	/**
59
+	 * @throws ValidationException
60
+	 */
61
+	public function testValidateImage()
62
+	{
63
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
64
+		$object->ImageID = null;
65
+		$this->setExpectedException(ValidationException::class);
66
+		$object->write();
67
+
68
+		$base->ImageID = 1;
69
+		$this->assertGreaterThan(0, $object->write());
70
+	}
71
+
72
+	/**
73
+	 * @throws ValidationException
74
+	 */
75
+	public function testValidateVideo()
76
+	{
77
+		$object = $this->objFromFixture(SlideImage::class, 'slide2');
78
+		$object->VideoID = null;
79
+		$this->setExpectedException(ValidationException::class);
80
+		$object->write();
81
+
82
+		$object->VideoID = 1;
83
+		$this->assertGreaterThan(0, $object->write());
84
+	}
85
+
86
+	/**
87
+	 * @throws ValidationException
88
+	 */
89
+	public function testValidateText()
90
+	{
91
+		$object = $this->objFromFixture(SlideImage::class, 'slide3');
92
+		$description = $object->Description;
93
+
94
+		$object->Description = null;
95
+		$this->setExpectedException(ValidationException::class);
96
+		$object->write();
97
+
98
+		$object->Description = $description;
99
+		$this->assertGreaterThan(0, $object->write());
100
+	}
101
+
102
+	/**
103
+	 *
104
+	 */
105
+	public function testProvidePermissions()
106
+	{
107
+		$object = SlideImage::singleton();
108
+
109
+		$expected = [
110
+			'Slide_EDIT' => 'Slide Edit',
111
+			'Slide_DELETE' => 'Slide Delete',
112
+			'Slide_CREATE' => 'Slide Create',
113
+		];
114
+
115
+		$this->assertEquals($expected, $object->providePermissions());
116
+	}
117
+
118
+	/**
119
+	 *
120
+	 */
121
+	public function testCanCreate()
122
+	{
123
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
124
+		$admin = $this->objFromFixture(Member::class, 'admin');
125
+		$this->assertTrue($object->canCreate($admin));
126
+
127
+		$author = $this->objFromFixture(Member::class, 'author');
128
+		$this->assertTrue($object->canCreate($author));
129
+
130
+		$member = $this->objFromFixture(Member::class, 'default');
131
+		$this->assertFalse($object->canCreate($member));
132
+	}
133
+
134
+	/**
135
+	 *
136
+	 */
137
+	public function testCanEdit()
138
+	{
139
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
140
+		$admin = $this->objFromFixture(Member::class, 'admin');
141
+		$this->assertTrue($object->canEdit($admin));
142
+
143
+		$author = $this->objFromFixture(Member::class, 'author');
144
+		$this->assertTrue($object->canEdit($author));
145
+
146
+		$member = $this->objFromFixture(Member::class, 'default');
147
+		$this->assertFalse($object->canEdit($member));
148
+	}
149
+
150
+	/**
151
+	 *
152
+	 */
153
+	public function testCanDelete()
154
+	{
155
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
156
+		$admin = $this->objFromFixture(Member::class, 'admin');
157
+		$this->assertTrue($object->canDelete($admin));
158
+
159
+		$author = $this->objFromFixture(Member::class, 'author');
160
+		$this->assertTrue($object->canDelete($author));
161
+
162
+		$member = $this->objFromFixture(Member::class, 'default');
163
+		$this->assertFalse($object->canDelete($member));
164
+	}
165
+
166
+	/**
167
+	 *
168
+	 */
169
+	public function testCanView()
170
+	{
171
+		$object = $this->objFromFixture(SlideImage::class, 'slide1');
172
+		$admin = $this->objFromFixture(Member::class, 'admin');
173
+		$this->assertTrue($object->canView($admin));
174
+
175
+		$author = $this->objFromFixture(Member::class, 'author');
176
+		$this->assertTrue($object->canView($author));
177
+
178
+		$member = $this->objFromFixture(Member::class, 'default');
179
+		$this->assertTrue($object->canView($member));
180
+	}
181
+
182
+	/**
183
+	 *
184
+	 */
185
+	public function testImageSizeLimit()
186
+	{
187
+		$default = 512000;
188
+		$this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $default);
189
+
190
+		$new = 1024000;
191
+		Config::modify()->update(SlideImage::class, 'image_size_limit', $new);
192
+		$this->assertEquals(Config::modify()->get(SlideImage::class, 'image_size_limit'), $new);
193
+	}
194
+
195
+	/**
196
+	 *
197
+	 */
198
+	public function testRenderWith()
199
+	{
200
+		$this->markTestSkipped("Todo SlideImageText::testRenderWith()");
201
+		//$slide = SlideImage::singleton();
202
+
203
+		//$this->assertInstanceOf(DBHTMLText::class, $slide->renderWith());
204
+	}
205
+
206
+	/**
207
+	 *
208
+	 */
209
+	public function testForTemplate()
210
+	{
211
+		$this->markTestSkipped("Todo SlideImageText::testForTemplate()");
212
+		//$slide = SlideImage::singleton();
213
+
214
+		//$this->assertInstanceOf(DBHTMLText::class, $slide->forTemplate());
215
+	}
216 216
 }
Please login to merge, or discard this patch.
tests/TestPage.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
  */
12 12
 class TestPage extends \Page implements TestOnly
13 13
 {
14
-    private static $slide_tab_title = '';
14
+	private static $slide_tab_title = '';
15 15
 
16
-    private static $table_name = 'FlexsliderTestPage';
16
+	private static $table_name = 'FlexsliderTestPage';
17 17
 }
Please login to merge, or discard this patch.
tests/FlexSliderTest.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -12,91 +12,91 @@
 block discarded – undo
12 12
 
13 13
 class FlexSliderTest extends SapphireTest
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected static $extra_dataobjects = [
19
-        TestPage::class,
20
-    ];
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected static $extra_dataobjects = [
19
+		TestPage::class,
20
+	];
21 21
 
22
-    /**
23
-     * @var string
24
-     */
25
-    protected static $fixture_file = 'fixtures.yml';
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected static $fixture_file = 'fixtures.yml';
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    protected static $required_extensions = [
31
-        TestPage::class => [
32
-            FlexSlider::class,
33
-        ],
34
-    ];
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected static $required_extensions = [
31
+		TestPage::class => [
32
+			FlexSlider::class,
33
+		],
34
+	];
35 35
 
36
-    /**
37
-     *
38
-     */
39
-    public function testTabNameConfig()
40
-    {
41
-        $page = TestPage::create();
42
-        $page->write();
43
-        $pageFields = $page->getCMSFields();
44
-        $this->assertNotNull($pageFields->dataFieldByName('Slides'));
36
+	/**
37
+	 *
38
+	 */
39
+	public function testTabNameConfig()
40
+	{
41
+		$page = TestPage::create();
42
+		$page->write();
43
+		$pageFields = $page->getCMSFields();
44
+		$this->assertNotNull($pageFields->dataFieldByName('Slides'));
45 45
 
46
-        Config::modify()
47
-            ->update(TestPage::class, 'slide_tab_title', 'MyCustomSlideTitle');
48
-        $page2 = TestPage::create();
49
-        $page2->write();
50
-        $page2Fields = $page2->getCMSFields();
51
-        $this->assertNull($page2Fields->fieldByName('Root.Slides'));
52
-        $this->assertNotNull($page2Fields->fieldByName('Root.MyCustomSlideTitle'));
53
-    }
46
+		Config::modify()
47
+			->update(TestPage::class, 'slide_tab_title', 'MyCustomSlideTitle');
48
+		$page2 = TestPage::create();
49
+		$page2->write();
50
+		$page2Fields = $page2->getCMSFields();
51
+		$this->assertNull($page2Fields->fieldByName('Root.Slides'));
52
+		$this->assertNotNull($page2Fields->fieldByName('Root.MyCustomSlideTitle'));
53
+	}
54 54
 
55
-    /**
56
-     *
57
-     */
58
-    public function testUpdateCMSFields()
59
-    {
60
-        $object = TestPage::create();
61
-        $fields = $object->getCMSFields();
62
-        $this->assertNull($fields->dataFieldByName('Slides'));
55
+	/**
56
+	 *
57
+	 */
58
+	public function testUpdateCMSFields()
59
+	{
60
+		$object = TestPage::create();
61
+		$fields = $object->getCMSFields();
62
+		$this->assertNull($fields->dataFieldByName('Slides'));
63 63
 
64
-        $object->write();
65
-        $fields = $object->getCMSFields();
66
-        $this->assertInstanceOf(FieldList::class, $fields);
67
-        $this->assertNotNull($fields->dataFieldbyName('Slides'));
68
-    }
64
+		$object->write();
65
+		$fields = $object->getCMSFields();
66
+		$this->assertInstanceOf(FieldList::class, $fields);
67
+		$this->assertNotNull($fields->dataFieldbyName('Slides'));
68
+	}
69 69
 
70
-    /**
71
-     *
72
-     */
73
-    public function testGetSlideshow()
74
-    {
75
-        $object = TestPage::create();
76
-        $object->write();
77
-        $slide1 = $this->objFromFixture(SlideImage::class, 'slide1');
78
-        $image = $this->objFromFixture(Image::class, 'image1');
79
-        $slide1->ImageID = $image->ID;
80
-        $object->Slides()->add($slide1);
81
-        $slides = $object->getSlideShow();
82
-        $this->assertInstanceOf(DataList::class, $slides);
83
-    }
70
+	/**
71
+	 *
72
+	 */
73
+	public function testGetSlideshow()
74
+	{
75
+		$object = TestPage::create();
76
+		$object->write();
77
+		$slide1 = $this->objFromFixture(SlideImage::class, 'slide1');
78
+		$image = $this->objFromFixture(Image::class, 'image1');
79
+		$slide1->ImageID = $image->ID;
80
+		$object->Slides()->add($slide1);
81
+		$slides = $object->getSlideShow();
82
+		$this->assertInstanceOf(DataList::class, $slides);
83
+	}
84 84
 
85
-    /**
86
-     *
87
-     */
88
-    public function testGetSlideshowSpeed()
89
-    {
90
-        /** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
91
-        $object = TestPage::create();
92
-        $object->FlexSliderSpeed = 0;
93
-        $this->assertEquals(
94
-            Config::inst()->get(FlexSlider::class, 'flex_slider_speed') * 1000,
95
-            $object->getSlideshowSpeed()
96
-        );
85
+	/**
86
+	 *
87
+	 */
88
+	public function testGetSlideshowSpeed()
89
+	{
90
+		/** @var \Dynamic\FlexSlider\ORM\FlexSlider|\Page $object */
91
+		$object = TestPage::create();
92
+		$object->FlexSliderSpeed = 0;
93
+		$this->assertEquals(
94
+			Config::inst()->get(FlexSlider::class, 'flex_slider_speed') * 1000,
95
+			$object->getSlideshowSpeed()
96
+		);
97 97
 
98
-        $object->FlexSliderSpeed = 0.5;
99
-        $object->write();
100
-        $this->assertEquals(500, $object->getSlideshowSpeed());
101
-    }
98
+		$object->FlexSliderSpeed = 0.5;
99
+		$object->write();
100
+		$this->assertEquals(500, $object->getSlideshowSpeed());
101
+	}
102 102
 }
Please login to merge, or discard this patch.
src/Task/DefaultSlideTypeTask.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -12,61 +12,61 @@
 block discarded – undo
12 12
  */
13 13
 class DefaultSlideTypeTask extends BuildTask
14 14
 {
15
-    /**
16
-     * @var string
17
-     */
18
-    private static $segment = 'default-slide-type-task';
15
+	/**
16
+	 * @var string
17
+	 */
18
+	private static $segment = 'default-slide-type-task';
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $title = 'Flexslider - Default Slide Type Task';
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $title = 'Flexslider - Default Slide Type Task';
24 24
 
25
-    /**
26
-     * @param \SilverStripe\Control\HTTPRequest $request
27
-     */
28
-    public function run($request)
29
-    {
30
-        $this->setDefaults();
31
-    }
25
+	/**
26
+	 * @param \SilverStripe\Control\HTTPRequest $request
27
+	 */
28
+	public function run($request)
29
+	{
30
+		$this->setDefaults();
31
+	}
32 32
 
33
-    /**
34
-     *
35
-     */
36
-    protected function setDefaults()
37
-    {
38
-        $default = SlideImage::singleton()->config()->get('defaults');
33
+	/**
34
+	 *
35
+	 */
36
+	protected function setDefaults()
37
+	{
38
+		$default = SlideImage::singleton()->config()->get('defaults');
39 39
 
40
-        if (isset($default['SlideType'])) {
41
-            $baseTable = SlideImage::singleton()->baseTable();
40
+		if (isset($default['SlideType'])) {
41
+			$baseTable = SlideImage::singleton()->baseTable();
42 42
 
43
-            $tables = [
44
-                $baseTable,
45
-                "{$baseTable}_Versions",
46
-                "{$baseTable}_Live",
47
-            ];
43
+			$tables = [
44
+				$baseTable,
45
+				"{$baseTable}_Versions",
46
+				"{$baseTable}_Live",
47
+			];
48 48
 
49
-            foreach ($tables as $table) {
50
-                $query = DB::query("SELECT * FROM \"{$table}\" WHERE \"SlideType\" IS NULL");
49
+			foreach ($tables as $table) {
50
+				$query = DB::query("SELECT * FROM \"{$table}\" WHERE \"SlideType\" IS NULL");
51 51
 
52
-                foreach ($this->yieldSingle($query) as $record) {
53
-                    DB::prepared_query(
54
-                        "UPDATE \"{$table}\" SET \"SlideType\" = ? WHERE \"ID\" = ?",
55
-                        [$default['SlideType'], $record['ID']]
56
-                    );
57
-                }
58
-            }
59
-        }
60
-    }
52
+				foreach ($this->yieldSingle($query) as $record) {
53
+					DB::prepared_query(
54
+						"UPDATE \"{$table}\" SET \"SlideType\" = ? WHERE \"ID\" = ?",
55
+						[$default['SlideType'], $record['ID']]
56
+					);
57
+				}
58
+			}
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @param $list
64
-     * @return \Generator
65
-     */
66
-    protected function yieldSingle($list)
67
-    {
68
-        foreach ($list as $item) {
69
-            yield $item;
70
-        }
71
-    }
62
+	/**
63
+	 * @param $list
64
+	 * @return \Generator
65
+	 */
66
+	protected function yieldSingle($list)
67
+	{
68
+		foreach ($list as $item) {
69
+			yield $item;
70
+		}
71
+	}
72 72
 }
Please login to merge, or discard this patch.
src/Task/SlideLinkTask.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -14,122 +14,122 @@
 block discarded – undo
14 14
  */
15 15
 class SlideLinkTask extends BuildTask
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $title = 'Flexslider - Slide Link Migration Task';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    private static $segment = 'slide-link-migration-task';
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    private $known_links = [];
31
-
32
-    /**
33
-     * @param \SilverStripe\Control\HTTPRequest $request
34
-     * @throws \SilverStripe\ORM\ValidationException
35
-     */
36
-    public function run($request)
37
-    {
38
-        $this->migrateLinks();
39
-    }
40
-
41
-    /**
42
-     * @throws \SilverStripe\ORM\ValidationException
43
-     */
44
-    protected function migrateLinks()
45
-    {
46
-        $baseTable = SlideImage::singleton()->baseTable();
47
-
48
-        $tables = [
49
-            $baseTable,
50
-            "{$baseTable}_Versions",
51
-            "{$baseTable}_Live",
52
-        ];
53
-
54
-        foreach ($tables as $table) {
55
-            foreach ($this->yieldSingle(DB::query("SELECT * FROM \"{$table}\"")) as $record) {
56
-                $linkID = $record['PageLinkID'];
57
-                $linkLabel = isset($record['LinkLabel']) ? $record['LinkLabel'] : null;
58
-
59
-                $slideLink = $this->findOrMakeLink($linkID, $linkLabel);
60
-
61
-                if ($slideLink !== false && $slideLink instanceof Link) {
62
-                    DB::prepared_query(
63
-                        "UPDATE \"{$table}\" SET \"SlideLinkID\" = ? WHERE \"ID\" = ?",
64
-                        [$slideLink->ID, $record['ID']]
65
-                    );
66
-                }
67
-            }
68
-        }
69
-    }
70
-
71
-    /**
72
-     * @param $list
73
-     * @return \Generator
74
-     */
75
-    private function yieldSingle($list)
76
-    {
77
-        foreach ($list as $item) {
78
-            yield $item;
79
-        }
80
-    }
81
-
82
-    /**
83
-     * @param int $linkID
84
-     * @param string $linkLabel
85
-     * @return bool|mixed|Link
86
-     * @throws \SilverStripe\ORM\ValidationException
87
-     */
88
-    private function findOrMakeLink($linkID = 0, $linkLabel = '')
89
-    {
90
-        if (!$linkID || !($page = SiteTree::get()->byID($linkID))) {
91
-            return false;
92
-        }
93
-
94
-        if (isset($this->getKnownLinks()[$linkID])) {
95
-            return $this->getKnownLinks()[$linkID];
96
-        }
97
-
98
-        $link = Link::create();
99
-        $link->Type = 'SiteTree';
100
-        $link->SiteTreeID = $linkID;
101
-        $link->Template = 'button';
102
-
103
-        if ($linkLabel !== null && $linkLabel !== '') {
104
-            $link->Title = $linkLabel;
105
-        } else {
106
-            $link->Title = $page->Title;
107
-        }
108
-
109
-        $link->write();
110
-
111
-        $this->addKnownLink($linkID, $link);
112
-
113
-        return $link;
114
-    }
115
-
116
-    /**
117
-     * @param $linkID
118
-     * @param $linkableLinkID
119
-     * @return $this
120
-     */
121
-    private function addKnownLink($linkID, $linkableLinkID)
122
-    {
123
-        $this->known_links[$linkID] = $linkableLinkID;
124
-
125
-        return $this;
126
-    }
127
-
128
-    /**
129
-     * @return array
130
-     */
131
-    private function getKnownLinks()
132
-    {
133
-        return $this->known_links;
134
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $title = 'Flexslider - Slide Link Migration Task';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	private static $segment = 'slide-link-migration-task';
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private $known_links = [];
31
+
32
+	/**
33
+	 * @param \SilverStripe\Control\HTTPRequest $request
34
+	 * @throws \SilverStripe\ORM\ValidationException
35
+	 */
36
+	public function run($request)
37
+	{
38
+		$this->migrateLinks();
39
+	}
40
+
41
+	/**
42
+	 * @throws \SilverStripe\ORM\ValidationException
43
+	 */
44
+	protected function migrateLinks()
45
+	{
46
+		$baseTable = SlideImage::singleton()->baseTable();
47
+
48
+		$tables = [
49
+			$baseTable,
50
+			"{$baseTable}_Versions",
51
+			"{$baseTable}_Live",
52
+		];
53
+
54
+		foreach ($tables as $table) {
55
+			foreach ($this->yieldSingle(DB::query("SELECT * FROM \"{$table}\"")) as $record) {
56
+				$linkID = $record['PageLinkID'];
57
+				$linkLabel = isset($record['LinkLabel']) ? $record['LinkLabel'] : null;
58
+
59
+				$slideLink = $this->findOrMakeLink($linkID, $linkLabel);
60
+
61
+				if ($slideLink !== false && $slideLink instanceof Link) {
62
+					DB::prepared_query(
63
+						"UPDATE \"{$table}\" SET \"SlideLinkID\" = ? WHERE \"ID\" = ?",
64
+						[$slideLink->ID, $record['ID']]
65
+					);
66
+				}
67
+			}
68
+		}
69
+	}
70
+
71
+	/**
72
+	 * @param $list
73
+	 * @return \Generator
74
+	 */
75
+	private function yieldSingle($list)
76
+	{
77
+		foreach ($list as $item) {
78
+			yield $item;
79
+		}
80
+	}
81
+
82
+	/**
83
+	 * @param int $linkID
84
+	 * @param string $linkLabel
85
+	 * @return bool|mixed|Link
86
+	 * @throws \SilverStripe\ORM\ValidationException
87
+	 */
88
+	private function findOrMakeLink($linkID = 0, $linkLabel = '')
89
+	{
90
+		if (!$linkID || !($page = SiteTree::get()->byID($linkID))) {
91
+			return false;
92
+		}
93
+
94
+		if (isset($this->getKnownLinks()[$linkID])) {
95
+			return $this->getKnownLinks()[$linkID];
96
+		}
97
+
98
+		$link = Link::create();
99
+		$link->Type = 'SiteTree';
100
+		$link->SiteTreeID = $linkID;
101
+		$link->Template = 'button';
102
+
103
+		if ($linkLabel !== null && $linkLabel !== '') {
104
+			$link->Title = $linkLabel;
105
+		} else {
106
+			$link->Title = $page->Title;
107
+		}
108
+
109
+		$link->write();
110
+
111
+		$this->addKnownLink($linkID, $link);
112
+
113
+		return $link;
114
+	}
115
+
116
+	/**
117
+	 * @param $linkID
118
+	 * @param $linkableLinkID
119
+	 * @return $this
120
+	 */
121
+	private function addKnownLink($linkID, $linkableLinkID)
122
+	{
123
+		$this->known_links[$linkID] = $linkableLinkID;
124
+
125
+		return $this;
126
+	}
127
+
128
+	/**
129
+	 * @return array
130
+	 */
131
+	private function getKnownLinks()
132
+	{
133
+		return $this->known_links;
134
+	}
135 135
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
                 $slideLink = $this->findOrMakeLink($linkID, $linkLabel);
60 60
 
61
-                if ($slideLink !== false && $slideLink instanceof Link) {
61
+                if ($slideLink!==false && $slideLink instanceof Link) {
62 62
                     DB::prepared_query(
63 63
                         "UPDATE \"{$table}\" SET \"SlideLinkID\" = ? WHERE \"ID\" = ?",
64 64
                         [$slideLink->ID, $record['ID']]
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $link->SiteTreeID = $linkID;
101 101
         $link->Template = 'button';
102 102
 
103
-        if ($linkLabel !== null && $linkLabel !== '') {
103
+        if ($linkLabel!==null && $linkLabel!=='') {
104 104
             $link->Title = $linkLabel;
105 105
         } else {
106 106
             $link->Title = $page->Title;
Please login to merge, or discard this patch.
src/Task/SlideThumbnailNavMigrationTask.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -16,91 +16,91 @@
 block discarded – undo
16 16
  */
17 17
 class SlideThumbnailNavMigrationTask extends BuildTask
18 18
 {
19
-    /**
20
-     * @var string
21
-     */
22
-    protected $title = 'FlexSlider - Default Values';
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected $title = 'FlexSlider - Default Values';
23 23
 
24
-    /**
25
-     * @var string
26
-     */
27
-    protected $description = 'Set default values for slider after the thumbnail nav update';
24
+	/**
25
+	 * @var string
26
+	 */
27
+	protected $description = 'Set default values for slider after the thumbnail nav update';
28 28
 
29
-    /**
30
-     * @var string
31
-     */
32
-    private static $segment = 'slide-thumbnail-nav-migration-task';
29
+	/**
30
+	 * @var string
31
+	 */
32
+	private static $segment = 'slide-thumbnail-nav-migration-task';
33 33
 
34
-    /**
35
-     * @var bool
36
-     */
37
-    protected $enabled = true;
34
+	/**
35
+	 * @var bool
36
+	 */
37
+	protected $enabled = true;
38 38
 
39
-    /**
40
-     * @param $request
41
-     */
42
-    public function run($request)
43
-    {
44
-        $this->defaultSliderSettings();
45
-    }
39
+	/**
40
+	 * @param $request
41
+	 */
42
+	public function run($request)
43
+	{
44
+		$this->defaultSliderSettings();
45
+	}
46 46
 
47
-    /**
48
-     * @param $class
49
-     * @return \Generator
50
-     */
51
-    protected function getObjectSet($class)
52
-    {
53
-        foreach ($class::get() as $object) {
54
-            yield $object;
55
-        }
56
-    }
47
+	/**
48
+	 * @param $class
49
+	 * @return \Generator
50
+	 */
51
+	protected function getObjectSet($class)
52
+	{
53
+		foreach ($class::get() as $object) {
54
+			yield $object;
55
+		}
56
+	}
57 57
 
58
-    /**
59
-     *
60
-     */
61
-    public function defaultSliderSettings()
62
-    {
63
-        $ct = 0;
58
+	/**
59
+	 *
60
+	 */
61
+	public function defaultSliderSettings()
62
+	{
63
+		$ct = 0;
64 64
 
65
-        $objects = ClassInfo::subclassesFor(DataObject::class);
65
+		$objects = ClassInfo::subclassesFor(DataObject::class);
66 66
 
67
-        if ($objects) {
68
-            unset($objects[DataObject::class]);
69
-            foreach ($objects as $object) {
70
-                if ($object::singleton()->hasExtension(FlexSlider::class)) {
71
-                    foreach ($this->getObjectSet($object) as $result) {
72
-                        $result->Loop = 1;
73
-                        $result->Animate = 1;
74
-                        $result->SliderControlNav = 0;
75
-                        $result->SliderDirectionNav = 1;
76
-                        $result->CarouselControlNav = 0;
77
-                        $result->CarouselDirectionNav = 1;
78
-                        $result->CarouselThumbnailCt = 6;
79
-                        if ($result instanceof SiteTree || $object::singleton()->hasExtension(Versioned::class)) {
80
-                            $result->writeToStage('Stage');
81
-                            if ($result->isPublished()) {
82
-                                $result->publishRecursive();
83
-                            }
84
-                        } else {
85
-                            $result->write();
86
-                        }
87
-                        $ct++;
88
-                    }
89
-                }
90
-            }
91
-        }
92
-        static::write_message($ct . " Sliders updated");
93
-    }
67
+		if ($objects) {
68
+			unset($objects[DataObject::class]);
69
+			foreach ($objects as $object) {
70
+				if ($object::singleton()->hasExtension(FlexSlider::class)) {
71
+					foreach ($this->getObjectSet($object) as $result) {
72
+						$result->Loop = 1;
73
+						$result->Animate = 1;
74
+						$result->SliderControlNav = 0;
75
+						$result->SliderDirectionNav = 1;
76
+						$result->CarouselControlNav = 0;
77
+						$result->CarouselDirectionNav = 1;
78
+						$result->CarouselThumbnailCt = 6;
79
+						if ($result instanceof SiteTree || $object::singleton()->hasExtension(Versioned::class)) {
80
+							$result->writeToStage('Stage');
81
+							if ($result->isPublished()) {
82
+								$result->publishRecursive();
83
+							}
84
+						} else {
85
+							$result->write();
86
+						}
87
+						$ct++;
88
+					}
89
+				}
90
+			}
91
+		}
92
+		static::write_message($ct . " Sliders updated");
93
+	}
94 94
 
95
-    /**
96
-     * @param $message
97
-     */
98
-    protected static function write_message($message)
99
-    {
100
-        if (Director::is_cli()) {
101
-            echo "{$message}\n";
102
-        } else {
103
-            echo "{$message}<br><br>";
104
-        }
105
-    }
95
+	/**
96
+	 * @param $message
97
+	 */
98
+	protected static function write_message($message)
99
+	{
100
+		if (Director::is_cli()) {
101
+			echo "{$message}\n";
102
+		} else {
103
+			echo "{$message}<br><br>";
104
+		}
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
                 }
90 90
             }
91 91
         }
92
-        static::write_message($ct . " Sliders updated");
92
+        static::write_message($ct." Sliders updated");
93 93
     }
94 94
 
95 95
     /**
Please login to merge, or discard this patch.
src/Model/SlideImage.php 2 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -36,312 +36,312 @@
 block discarded – undo
36 36
  */
37 37
 class SlideImage extends DataObject implements PermissionProvider
38 38
 {
39
-    /**
40
-     * @var string
41
-     */
42
-    private static $singular_name = 'Slide';
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    private static $plural_name = 'Slides';
48
-
49
-    /**
50
-     * @var array
51
-     */
52
-    private static $db = [
53
-        'Name' => 'Varchar(255)',
54
-        'Headline' => 'Varchar(255)',
55
-        'Description' => 'Text',
56
-        'SortOrder' => 'Int',
57
-        'SlideType' => 'Varchar',
58
-    ];
59
-
60
-    /**
61
-     * @var array
62
-     */
63
-    private static $has_one = [
64
-        'Image' => Image::class,
65
-        'Video' => EmbeddedObject::class,
66
-        'Page' => \Page::class,
67
-        'PageLink' => SiteTree::class,
68
-        'SlideLink' => Link::class,
69
-    ];
70
-
71
-    /**
72
-     * @var array
73
-     */
74
-    private static $owns = [
75
-        'Image',
76
-    ];
77
-
78
-    /**
79
-     * @var string
80
-     */
81
-    private static $table_name = 'SlideImage';
82
-
83
-    /**
84
-     * @var string
85
-     */
86
-    private static $default_sort = 'SortOrder';
87
-
88
-    /**
89
-     * Adds Publish button to SlideImage record
90
-     *
91
-     * @var bool
92
-     */
93
-    private static $versioned_gridfield_extensions = true;
94
-
95
-    /**
96
-     * @var array
97
-     */
98
-    private static $defaults = [
99
-        'SlideType' => 'Image',
100
-    ];
101
-
102
-    /**
103
-     * @var array
104
-     */
105
-    private static $summary_fields = [
106
-        'Image.CMSThumbnail' => 'Image',
107
-        'Name' => 'Name',
108
-    ];
109
-
110
-    /**
111
-     * @var array
112
-     */
113
-    private static $searchable_fields = [
114
-        'Name',
115
-        'Headline',
116
-        'Description',
117
-    ];
118
-
119
-    /**
120
-     * @var int
121
-     */
122
-    private static $image_size_limit = 512000;
123
-
124
-    /**
125
-     * @var array
126
-     */
127
-    private static $slide_types = [
128
-        'Image',
129
-        'Video',
130
-        'Text',
131
-    ];
132
-
133
-    /**
134
-     * @param bool $includerelations
135
-     * @return array
136
-     */
137
-    public function fieldLabels($includerelations = true)
138
-    {
139
-        $labels = parent::fieldLabels($includerelations);
140
-
141
-        $labels['Name'] = _t(__CLASS__ . '.NAME', 'Name');
142
-        $labels['Headline'] = _t(__CLASS__ . '.HEADLINE', 'Headline');
143
-        $labels['Description'] = _t(__CLASS__ . '.DESCRIPTION', 'Description');
144
-        $labels['SlideLinkID'] =  _t(__CLASS__ . '.PAGE_LINK', "Call to action link");
145
-        $labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image');
146
-        $labels['SlideType'] = _t(__CLASS__ . '.SlideType', 'Image or Video');
147
-        $labels['Video'] = _t(__CLASS__ . '.VideoLabel', 'Video URL');
148
-
149
-        return $labels;
150
-    }
151
-
152
-    /**
153
-     * @return \SilverStripe\Forms\FieldList
154
-     */
155
-    public function getCMSFields()
156
-    {
157
-        $this->beforeUpdateCMSFields(function ($fields) {
158
-            $fields->removeByName([
159
-                'ShowSlide',
160
-                'SortOrder',
161
-                'PageID',
162
-                'Image',
163
-                'SlideType',
164
-                'Video',
165
-                'VideoID',
166
-                'SlideLinkID',
167
-            ]);
168
-
169
-            // Name
170
-            $fields->dataFieldByName('Name')
171
-                ->setDescription(
172
-                    _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
173
-                );
174
-
175
-            // Headline
176
-            $fields->dataFieldByName('Headline')
177
-                ->setDescription(
178
-                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
179
-                );
180
-
181
-            // Description
182
-            $fields->dataFieldByName('Description')
183
-                ->setDescription(
184
-                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
185
-                );
186
-
187
-            // Page link
188
-            $fields->replaceField(
189
-                'PageLinkID',
190
-                LinkField::create('SlideLinkID', $this->fieldLabel('SlideLinkID'))
191
-            );
192
-
193
-            // Image
194
-            $image = UploadField::create('Image', $this->fieldLabel('Image'))
195
-                ->setFolderName('Uploads/SlideImages');
196
-
197
-            $image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
198
-
199
-            $fields->addFieldToTab(
200
-                'Root.Main',
201
-                CompositeField::create(FieldList::create(
202
-                    DropdownField::create('SlideType', $this->fieldLabel('SlideType'))
203
-                        ->setSource($this->getTypeSource()),
204
-                    Wrapper::create(
205
-                        $image
206
-                    )->displayIf('SlideType')->isEqualTo('Image')->orIf('SlideType')->isEqualTo('Video')->end(),
207
-                    Wrapper::create(
208
-                        $videoField = EmbeddedObjectField::create('Video', $this->fieldLabel('Video'))
209
-                            ->setDescription(_t(__CLASS__ . '.VideoDescription', 'Supported links: YouTube, Vimeo'))
210
-                    )->displayIf('SlideType')->isEqualTo('Video')->end()
211
-                ))->setName('MediaFields'),
212
-                'Description'
213
-            );
214
-        });
215
-
216
-        $fields = parent::getCMSFields();
217
-
218
-        $this->extend('updateSlideImageFields', $fields);
219
-
220
-        return $fields;
221
-    }
222
-
223
-    /**
224
-     * @return \SilverStripe\ORM\ValidationResult
225
-     */
226
-    public function validate()
227
-    {
228
-        $result = parent::validate();
229
-
230
-        if (!$this->Name) {
231
-            $result->addError(
232
-                _t(__CLASS__ . '.NAME_REQUIRED', 'A Name is required before you can save')
233
-            );
234
-        }
235
-
236
-        $types = $this->getTypeSource();
237
-
238
-        if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) {
239
-            $result->addError(
240
-                _t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save')
241
-            );
242
-        }
243
-
244
-        if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) {
245
-            $result->addError(
246
-                _t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save')
247
-            );
248
-        }
249
-
250
-        if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) {
251
-            $result->addError(
252
-                _t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save')
253
-            );
254
-        }
255
-
256
-        return $result;
257
-    }
258
-
259
-    /**
260
-     * @return array
261
-     */
262
-    public function providePermissions()
263
-    {
264
-        return [
265
-            'Slide_EDIT' => 'Slide Edit',
266
-            'Slide_DELETE' => 'Slide Delete',
267
-            'Slide_CREATE' => 'Slide Create',
268
-        ];
269
-    }
270
-
271
-    /**
272
-     * @param null $member
273
-     * @param array $context
274
-     *
275
-     * @return bool|int
276
-     */
277
-    public function canCreate($member = null, $context = [])
278
-    {
279
-        return Permission::check('Slide_CREATE', 'any', $member);
280
-    }
281
-
282
-    /**
283
-     * @param null $member
284
-     * @param array $context
285
-     *
286
-     * @return bool|int
287
-     */
288
-    public function canEdit($member = null, $context = [])
289
-    {
290
-        return Permission::check('Slide_EDIT', 'any', $member);
291
-    }
292
-
293
-    /**
294
-     * @param null $member
295
-     * @param array $context
296
-     *
297
-     * @return bool|int
298
-     */
299
-    public function canDelete($member = null, $context = [])
300
-    {
301
-        return Permission::check('Slide_DELETE', 'any', $member);
302
-    }
303
-
304
-    /**
305
-     * @param null $member
306
-     * @param array $context
307
-     *
308
-     * @return bool
309
-     */
310
-    public function canView($member = null, $context = [])
311
-    {
312
-        return true;
313
-    }
314
-
315
-    /**
316
-     * @return array
317
-     */
318
-    public function getTypeSource()
319
-    {
320
-        $types = $this->config()->get('slide_types');
321
-        asort($types);
322
-        return array_combine($types, $types);
323
-    }
324
-
325
-    /**
326
-     * @param null $template
327
-     * @param null $customFields
328
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
329
-     */
330
-    public function renderWith($template = null, $customFields = null)
331
-    {
332
-        if ($template === null) {
333
-            $template = static::class;
334
-            $template = ($this->SlideType) ? $template . "_{$this->SlideType}" : '';
335
-        }
336
-
337
-        return parent::renderWith($template);
338
-    }
339
-
340
-    /**
341
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
342
-     */
343
-    public function forTemplate()
344
-    {
345
-        return $this->renderWith();
346
-    }
39
+	/**
40
+	 * @var string
41
+	 */
42
+	private static $singular_name = 'Slide';
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	private static $plural_name = 'Slides';
48
+
49
+	/**
50
+	 * @var array
51
+	 */
52
+	private static $db = [
53
+		'Name' => 'Varchar(255)',
54
+		'Headline' => 'Varchar(255)',
55
+		'Description' => 'Text',
56
+		'SortOrder' => 'Int',
57
+		'SlideType' => 'Varchar',
58
+	];
59
+
60
+	/**
61
+	 * @var array
62
+	 */
63
+	private static $has_one = [
64
+		'Image' => Image::class,
65
+		'Video' => EmbeddedObject::class,
66
+		'Page' => \Page::class,
67
+		'PageLink' => SiteTree::class,
68
+		'SlideLink' => Link::class,
69
+	];
70
+
71
+	/**
72
+	 * @var array
73
+	 */
74
+	private static $owns = [
75
+		'Image',
76
+	];
77
+
78
+	/**
79
+	 * @var string
80
+	 */
81
+	private static $table_name = 'SlideImage';
82
+
83
+	/**
84
+	 * @var string
85
+	 */
86
+	private static $default_sort = 'SortOrder';
87
+
88
+	/**
89
+	 * Adds Publish button to SlideImage record
90
+	 *
91
+	 * @var bool
92
+	 */
93
+	private static $versioned_gridfield_extensions = true;
94
+
95
+	/**
96
+	 * @var array
97
+	 */
98
+	private static $defaults = [
99
+		'SlideType' => 'Image',
100
+	];
101
+
102
+	/**
103
+	 * @var array
104
+	 */
105
+	private static $summary_fields = [
106
+		'Image.CMSThumbnail' => 'Image',
107
+		'Name' => 'Name',
108
+	];
109
+
110
+	/**
111
+	 * @var array
112
+	 */
113
+	private static $searchable_fields = [
114
+		'Name',
115
+		'Headline',
116
+		'Description',
117
+	];
118
+
119
+	/**
120
+	 * @var int
121
+	 */
122
+	private static $image_size_limit = 512000;
123
+
124
+	/**
125
+	 * @var array
126
+	 */
127
+	private static $slide_types = [
128
+		'Image',
129
+		'Video',
130
+		'Text',
131
+	];
132
+
133
+	/**
134
+	 * @param bool $includerelations
135
+	 * @return array
136
+	 */
137
+	public function fieldLabels($includerelations = true)
138
+	{
139
+		$labels = parent::fieldLabels($includerelations);
140
+
141
+		$labels['Name'] = _t(__CLASS__ . '.NAME', 'Name');
142
+		$labels['Headline'] = _t(__CLASS__ . '.HEADLINE', 'Headline');
143
+		$labels['Description'] = _t(__CLASS__ . '.DESCRIPTION', 'Description');
144
+		$labels['SlideLinkID'] =  _t(__CLASS__ . '.PAGE_LINK', "Call to action link");
145
+		$labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image');
146
+		$labels['SlideType'] = _t(__CLASS__ . '.SlideType', 'Image or Video');
147
+		$labels['Video'] = _t(__CLASS__ . '.VideoLabel', 'Video URL');
148
+
149
+		return $labels;
150
+	}
151
+
152
+	/**
153
+	 * @return \SilverStripe\Forms\FieldList
154
+	 */
155
+	public function getCMSFields()
156
+	{
157
+		$this->beforeUpdateCMSFields(function ($fields) {
158
+			$fields->removeByName([
159
+				'ShowSlide',
160
+				'SortOrder',
161
+				'PageID',
162
+				'Image',
163
+				'SlideType',
164
+				'Video',
165
+				'VideoID',
166
+				'SlideLinkID',
167
+			]);
168
+
169
+			// Name
170
+			$fields->dataFieldByName('Name')
171
+				->setDescription(
172
+					_t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
173
+				);
174
+
175
+			// Headline
176
+			$fields->dataFieldByName('Headline')
177
+				->setDescription(
178
+					_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
179
+				);
180
+
181
+			// Description
182
+			$fields->dataFieldByName('Description')
183
+				->setDescription(
184
+					_t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
185
+				);
186
+
187
+			// Page link
188
+			$fields->replaceField(
189
+				'PageLinkID',
190
+				LinkField::create('SlideLinkID', $this->fieldLabel('SlideLinkID'))
191
+			);
192
+
193
+			// Image
194
+			$image = UploadField::create('Image', $this->fieldLabel('Image'))
195
+				->setFolderName('Uploads/SlideImages');
196
+
197
+			$image->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
198
+
199
+			$fields->addFieldToTab(
200
+				'Root.Main',
201
+				CompositeField::create(FieldList::create(
202
+					DropdownField::create('SlideType', $this->fieldLabel('SlideType'))
203
+						->setSource($this->getTypeSource()),
204
+					Wrapper::create(
205
+						$image
206
+					)->displayIf('SlideType')->isEqualTo('Image')->orIf('SlideType')->isEqualTo('Video')->end(),
207
+					Wrapper::create(
208
+						$videoField = EmbeddedObjectField::create('Video', $this->fieldLabel('Video'))
209
+							->setDescription(_t(__CLASS__ . '.VideoDescription', 'Supported links: YouTube, Vimeo'))
210
+					)->displayIf('SlideType')->isEqualTo('Video')->end()
211
+				))->setName('MediaFields'),
212
+				'Description'
213
+			);
214
+		});
215
+
216
+		$fields = parent::getCMSFields();
217
+
218
+		$this->extend('updateSlideImageFields', $fields);
219
+
220
+		return $fields;
221
+	}
222
+
223
+	/**
224
+	 * @return \SilverStripe\ORM\ValidationResult
225
+	 */
226
+	public function validate()
227
+	{
228
+		$result = parent::validate();
229
+
230
+		if (!$this->Name) {
231
+			$result->addError(
232
+				_t(__CLASS__ . '.NAME_REQUIRED', 'A Name is required before you can save')
233
+			);
234
+		}
235
+
236
+		$types = $this->getTypeSource();
237
+
238
+		if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) {
239
+			$result->addError(
240
+				_t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save')
241
+			);
242
+		}
243
+
244
+		if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) {
245
+			$result->addError(
246
+				_t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save')
247
+			);
248
+		}
249
+
250
+		if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) {
251
+			$result->addError(
252
+				_t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save')
253
+			);
254
+		}
255
+
256
+		return $result;
257
+	}
258
+
259
+	/**
260
+	 * @return array
261
+	 */
262
+	public function providePermissions()
263
+	{
264
+		return [
265
+			'Slide_EDIT' => 'Slide Edit',
266
+			'Slide_DELETE' => 'Slide Delete',
267
+			'Slide_CREATE' => 'Slide Create',
268
+		];
269
+	}
270
+
271
+	/**
272
+	 * @param null $member
273
+	 * @param array $context
274
+	 *
275
+	 * @return bool|int
276
+	 */
277
+	public function canCreate($member = null, $context = [])
278
+	{
279
+		return Permission::check('Slide_CREATE', 'any', $member);
280
+	}
281
+
282
+	/**
283
+	 * @param null $member
284
+	 * @param array $context
285
+	 *
286
+	 * @return bool|int
287
+	 */
288
+	public function canEdit($member = null, $context = [])
289
+	{
290
+		return Permission::check('Slide_EDIT', 'any', $member);
291
+	}
292
+
293
+	/**
294
+	 * @param null $member
295
+	 * @param array $context
296
+	 *
297
+	 * @return bool|int
298
+	 */
299
+	public function canDelete($member = null, $context = [])
300
+	{
301
+		return Permission::check('Slide_DELETE', 'any', $member);
302
+	}
303
+
304
+	/**
305
+	 * @param null $member
306
+	 * @param array $context
307
+	 *
308
+	 * @return bool
309
+	 */
310
+	public function canView($member = null, $context = [])
311
+	{
312
+		return true;
313
+	}
314
+
315
+	/**
316
+	 * @return array
317
+	 */
318
+	public function getTypeSource()
319
+	{
320
+		$types = $this->config()->get('slide_types');
321
+		asort($types);
322
+		return array_combine($types, $types);
323
+	}
324
+
325
+	/**
326
+	 * @param null $template
327
+	 * @param null $customFields
328
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
329
+	 */
330
+	public function renderWith($template = null, $customFields = null)
331
+	{
332
+		if ($template === null) {
333
+			$template = static::class;
334
+			$template = ($this->SlideType) ? $template . "_{$this->SlideType}" : '';
335
+		}
336
+
337
+		return parent::renderWith($template);
338
+	}
339
+
340
+	/**
341
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
342
+	 */
343
+	public function forTemplate()
344
+	{
345
+		return $this->renderWith();
346
+	}
347 347
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
     {
139 139
         $labels = parent::fieldLabels($includerelations);
140 140
 
141
-        $labels['Name'] = _t(__CLASS__ . '.NAME', 'Name');
142
-        $labels['Headline'] = _t(__CLASS__ . '.HEADLINE', 'Headline');
143
-        $labels['Description'] = _t(__CLASS__ . '.DESCRIPTION', 'Description');
144
-        $labels['SlideLinkID'] =  _t(__CLASS__ . '.PAGE_LINK', "Call to action link");
145
-        $labels['Image'] = _t(__CLASS__ . '.IMAGE', 'Image');
146
-        $labels['SlideType'] = _t(__CLASS__ . '.SlideType', 'Image or Video');
147
-        $labels['Video'] = _t(__CLASS__ . '.VideoLabel', 'Video URL');
141
+        $labels['Name'] = _t(__CLASS__.'.NAME', 'Name');
142
+        $labels['Headline'] = _t(__CLASS__.'.HEADLINE', 'Headline');
143
+        $labels['Description'] = _t(__CLASS__.'.DESCRIPTION', 'Description');
144
+        $labels['SlideLinkID'] = _t(__CLASS__.'.PAGE_LINK', "Call to action link");
145
+        $labels['Image'] = _t(__CLASS__.'.IMAGE', 'Image');
146
+        $labels['SlideType'] = _t(__CLASS__.'.SlideType', 'Image or Video');
147
+        $labels['Video'] = _t(__CLASS__.'.VideoLabel', 'Video URL');
148 148
 
149 149
         return $labels;
150 150
     }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      */
155 155
     public function getCMSFields()
156 156
     {
157
-        $this->beforeUpdateCMSFields(function ($fields) {
157
+        $this->beforeUpdateCMSFields(function($fields) {
158 158
             $fields->removeByName([
159 159
                 'ShowSlide',
160 160
                 'SortOrder',
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
             // Name
170 170
             $fields->dataFieldByName('Name')
171 171
                 ->setDescription(
172
-                    _t(__CLASS__ . '.INTERNAL_USE', 'for internal reference only')
172
+                    _t(__CLASS__.'.INTERNAL_USE', 'for internal reference only')
173 173
                 );
174 174
 
175 175
             // Headline
176 176
             $fields->dataFieldByName('Headline')
177 177
                 ->setDescription(
178
-                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
178
+                    _t(__CLASS__.'.USED_IN_TEMPLATE', 'optional, used in template')
179 179
                 );
180 180
 
181 181
             // Description
182 182
             $fields->dataFieldByName('Description')
183 183
                 ->setDescription(
184
-                    _t(__CLASS__ . '.USED_IN_TEMPLATE', 'optional, used in template')
184
+                    _t(__CLASS__.'.USED_IN_TEMPLATE', 'optional, used in template')
185 185
                 );
186 186
 
187 187
             // Page link
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
                     )->displayIf('SlideType')->isEqualTo('Image')->orIf('SlideType')->isEqualTo('Video')->end(),
207 207
                     Wrapper::create(
208 208
                         $videoField = EmbeddedObjectField::create('Video', $this->fieldLabel('Video'))
209
-                            ->setDescription(_t(__CLASS__ . '.VideoDescription', 'Supported links: YouTube, Vimeo'))
209
+                            ->setDescription(_t(__CLASS__.'.VideoDescription', 'Supported links: YouTube, Vimeo'))
210 210
                     )->displayIf('SlideType')->isEqualTo('Video')->end()
211 211
                 ))->setName('MediaFields'),
212 212
                 'Description'
@@ -229,27 +229,27 @@  discard block
 block discarded – undo
229 229
 
230 230
         if (!$this->Name) {
231 231
             $result->addError(
232
-                _t(__CLASS__ . '.NAME_REQUIRED', 'A Name is required before you can save')
232
+                _t(__CLASS__.'.NAME_REQUIRED', 'A Name is required before you can save')
233 233
             );
234 234
         }
235 235
 
236 236
         $types = $this->getTypeSource();
237 237
 
238
-        if (isset($types['Video']) && $this->SlideType == 'Video' && !$this->VideoID) {
238
+        if (isset($types['Video']) && $this->SlideType=='Video' && !$this->VideoID) {
239 239
             $result->addError(
240
-                _t(__CLASS__ . '.VIDEO_REQUIRED', 'An Video Link is required before you can save')
240
+                _t(__CLASS__.'.VIDEO_REQUIRED', 'An Video Link is required before you can save')
241 241
             );
242 242
         }
243 243
 
244
-        if (isset($types['Image']) && $this->SlideType == 'Image' && !$this->ImageID) {
244
+        if (isset($types['Image']) && $this->SlideType=='Image' && !$this->ImageID) {
245 245
             $result->addError(
246
-                _t(__CLASS__ . '.IMAGE_REQUIRED', 'An Image is required before you can save')
246
+                _t(__CLASS__.'.IMAGE_REQUIRED', 'An Image is required before you can save')
247 247
             );
248 248
         }
249 249
 
250
-        if (isset($types['Text']) && $this->SlideType == 'Text' && !$this->Description) {
250
+        if (isset($types['Text']) && $this->SlideType=='Text' && !$this->Description) {
251 251
             $result->addError(
252
-                _t(__CLASS__ . '.DESCRIPTION_REQUIRED', 'A Description is required before you can save')
252
+                _t(__CLASS__.'.DESCRIPTION_REQUIRED', 'A Description is required before you can save')
253 253
             );
254 254
         }
255 255
 
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
      */
330 330
     public function renderWith($template = null, $customFields = null)
331 331
     {
332
-        if ($template === null) {
332
+        if ($template===null) {
333 333
             $template = static::class;
334
-            $template = ($this->SlideType) ? $template . "_{$this->SlideType}" : '';
334
+            $template = ($this->SlideType) ? $template."_{$this->SlideType}" : '';
335 335
         }
336 336
 
337 337
         return parent::renderWith($template);
Please login to merge, or discard this patch.
src/ORM/FlexSlider.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -109,63 +109,63 @@  discard block
 block discarded – undo
109 109
             ]);
110 110
             $SlidesField = GridField::create(
111 111
                 'Slides',
112
-                _t(__CLASS__ . '.SLIDES', 'Slides'),
112
+                _t(__CLASS__.'.SLIDES', 'Slides'),
113 113
                 $this->owner->Slides()->sort('SortOrder'),
114 114
                 $config
115 115
             );
116 116
 
117
-            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
117
+            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__.'.SLIDES', 'Slides');
118 118
 
119 119
             $animations = [];
120 120
             $animationOptions = $this->owner->dbObject('Animation')->getEnum();
121 121
             foreach ($animationOptions as $value) {
122
-                $animations[$value] = _t(__CLASS__ . ".$value", $value);
122
+                $animations[$value] = _t(__CLASS__.".$value", $value);
123 123
             }
124 124
 
125 125
             $fields->addFieldsToTab("Root.{$slideTitle}", [
126 126
                 $SlidesField,
127
-                ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
127
+                ToggleCompositeField::create('ConfigHD', _t(__CLASS__.'.SettingsLabel', 'Slider Settings'), [
128 128
                     DropdownField::create(
129 129
                         'Animation',
130
-                        _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
130
+                        _t(__CLASS__.'.ANIMATION_OPTION', 'Animation option'),
131 131
                         $animations
132 132
                     ),
133 133
                     CheckboxField::create(
134 134
                         'Animate',
135
-                        _t(__CLASS__ . '.ANIMATE', 'Animate automatically')
135
+                        _t(__CLASS__.'.ANIMATE', 'Animate automatically')
136 136
                     ),
137 137
                     CheckboxField::create(
138 138
                         'Loop',
139
-                        _t(__CLASS__ . '.LOOP', 'Loop the carousel')
139
+                        _t(__CLASS__.'.LOOP', 'Loop the carousel')
140 140
                     ),
141 141
                     CheckboxField::create(
142 142
                         'SliderControlNav',
143
-                        _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
143
+                        _t(__CLASS__.'.CONTROL_NAV', 'Show ControlNav')
144 144
                     ),
145 145
                     CheckboxField::create(
146 146
                         'SliderDirectionNav',
147
-                        _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
147
+                        _t(__CLASS__.'.DIRECTION_NAV', 'Show DirectionNav')
148 148
                     ),
149 149
                     CheckboxField::create(
150 150
                         'ThumbnailNav',
151
-                        _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
151
+                        _t(__CLASS__.'.THUMBNAIL_NAV', 'Thumbnail Navigation')
152 152
                     ),
153 153
                     //DisplayLogicWrapper::create(
154 154
                     CheckboxField::create(
155 155
                         'CarouselControlNav',
156
-                        _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156
+                        _t(__CLASS__.'.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
157 157
                     ),
158 158
                     CheckboxField::create(
159 159
                         'CarouselDirectionNav',
160
-                        _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160
+                        _t(__CLASS__.'.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
161 161
                     ),
162 162
                     NumericField::create(
163 163
                         'CarouselThumbnailCt',
164
-                        _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164
+                        _t(__CLASS__.'.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
165 165
                     ),
166 166
                     NumericField::create(
167 167
                         'FlexSliderSpeed',
168
-                        _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
168
+                        _t(__CLASS__.'.SLIDER_SPEED', 'Slider Speed')
169 169
                     )
170 170
                         ->setDescription('In Seconds')
171 171
                         ->setScale(2),
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     public function getCustomScript()
208 208
     {
209 209
         // Flexslider options
210
-        $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
210
+        $sync = ($this->owner->ThumbnailNav==true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
211 211
 
212 212
         $before = $this->owner->hasMethod('flexSliderBeforeAction')
213 213
             ? $this->owner->flexSliderBeforeAction()
@@ -226,18 +226,18 @@  discard block
 block discarded – undo
226 226
 
227 227
                          if(jQuery('.fs-carousel').eq(index).length) {
228 228
                              jQuery('.fs-carousel').eq(index).flexslider({
229
-                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ",
229
+                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean().",
230 230
                                 animation: 'slide',
231
-                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean() . ",
232
-                                controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean() . ",
233
-                                directionNav: " . $this->owner->obj('CarouselDirectionNav')->NiceAsBoolean() . ",
231
+                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean().",
232
+                                controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean().",
233
+                                directionNav: " . $this->owner->obj('CarouselDirectionNav')->NiceAsBoolean().",
234 234
                                 prevText: '',
235 235
                                 nextText: '',
236 236
                                 pausePlay: false,
237 237
                                 asNavFor: '.flexslider:eq('+index+')',
238
-                                minItems: " . $this->owner->obj('CarouselThumbnailCt') . ",
239
-                                maxItems: " . $this->owner->obj('CarouselThumbnailCt') . ",
240
-                                move: " . $this->owner->obj('CarouselThumbnailCt') . ",
238
+                                minItems: " . $this->owner->obj('CarouselThumbnailCt').",
239
+                                maxItems: " . $this->owner->obj('CarouselThumbnailCt').",
240
+                                move: " . $this->owner->obj('CarouselThumbnailCt').",
241 241
                                 itemWidth: 100,
242 242
                                 itemMargin: 10
243 243
                               });
@@ -245,22 +245,22 @@  discard block
 block discarded – undo
245 245
 
246 246
                         if(jQuery('.flexslider').eq(index).length){
247 247
                             jQuery('.flexslider').eq(index).flexslider({
248
-                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ",
249
-                                animation: '" . $this->owner->Animation . "',
250
-                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean() . ",
251
-                                controlNav: " . $this->owner->obj('SliderControlNav')->NiceAsBoolean() . ",
252
-                                directionNav: " . $this->owner->obj('SliderDirectionNav')->NiceAsBoolean() . ",
248
+                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean().",
249
+                                animation: '" . $this->owner->Animation."',
250
+                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean().",
251
+                                controlNav: " . $this->owner->obj('SliderControlNav')->NiceAsBoolean().",
252
+                                directionNav: " . $this->owner->obj('SliderDirectionNav')->NiceAsBoolean().",
253 253
                                 prevText: '',
254 254
                                 nextText: '',
255 255
                                 pauseOnAction: true,
256 256
                                 pauseOnHover: true,
257
-                                " . $sync . "
257
+                                " . $sync."
258 258
                                 start: function(slider){
259 259
                                   $('body').removeClass('loading');
260 260
                                 },
261
-                                before: " . $before . ',
262
-                                after: ' . $after . ',
263
-                                slideshowSpeed: ' . $speed . '
261
+                                before: " . $before.',
262
+                                after: ' . $after.',
263
+                                slideshowSpeed: ' . $speed.'
264 264
                             });
265 265
                         }
266 266
                     })
Please login to merge, or discard this 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.