Passed
Pull Request — 4.1 (#206)
by Jason
03:18
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/ORM/FlexSlider.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -37,189 +37,189 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class FlexSlider extends DataExtension
39 39
 {
40
-    use Configurable;
40
+	use Configurable;
41 41
 
42
-    /**
43
-     * @var array
44
-     */
45
-    private static $db = [
46
-        'Animation' => "Enum('slide, fade', 'slide')",
47
-        'Loop' => 'Boolean',
48
-        'Animate' => 'Boolean',
49
-        'ThumbnailNav' => 'Boolean',
50
-        'SliderControlNav' => 'Boolean',
51
-        'SliderDirectionNav' => 'Boolean',
52
-        'CarouselControlNav' => 'Boolean',
53
-        'CarouselDirectionNav' => 'Boolean',
54
-        'CarouselThumbnailCt' => 'Int',
55
-        'FlexSliderSpeed' => 'Double',
56
-    ];
42
+	/**
43
+	 * @var array
44
+	 */
45
+	private static $db = [
46
+		'Animation' => "Enum('slide, fade', 'slide')",
47
+		'Loop' => 'Boolean',
48
+		'Animate' => 'Boolean',
49
+		'ThumbnailNav' => 'Boolean',
50
+		'SliderControlNav' => 'Boolean',
51
+		'SliderDirectionNav' => 'Boolean',
52
+		'CarouselControlNav' => 'Boolean',
53
+		'CarouselDirectionNav' => 'Boolean',
54
+		'CarouselThumbnailCt' => 'Int',
55
+		'FlexSliderSpeed' => 'Double',
56
+	];
57 57
 
58
-    /**
59
-     * @var array
60
-     */
61
-    private static $has_many = [
62
-        'Slides' => SlideImage::class,
63
-    ];
58
+	/**
59
+	 * @var array
60
+	 */
61
+	private static $has_many = [
62
+		'Slides' => SlideImage::class,
63
+	];
64 64
 
65
-    /**
66
-     *
67
-     */
68
-    public function populateDefaults()
69
-    {
70
-        $this->owner->Loop = 1;
71
-        $this->owner->Animate = 1;
72
-        $this->owner->SliderControlNav = 0;
73
-        $this->owner->SliderDirectionNav = 1;
74
-        $this->owner->CarouselControlNav = 0;
75
-        $this->owner->CarouselDirectionNav = 1;
76
-        $this->owner->CarouselThumbnailCt = 6;
77
-        $this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
65
+	/**
66
+	 *
67
+	 */
68
+	public function populateDefaults()
69
+	{
70
+		$this->owner->Loop = 1;
71
+		$this->owner->Animate = 1;
72
+		$this->owner->SliderControlNav = 0;
73
+		$this->owner->SliderDirectionNav = 1;
74
+		$this->owner->CarouselControlNav = 0;
75
+		$this->owner->CarouselDirectionNav = 1;
76
+		$this->owner->CarouselThumbnailCt = 6;
77
+		$this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
78 78
 
79
-        return parent::populateDefaults();
80
-    }
79
+		return parent::populateDefaults();
80
+	}
81 81
 
82
-    /**
83
-     * @param FieldList $fields
84
-     */
85
-    public function updateCMSFields(FieldList $fields)
86
-    {
87
-        $fields->removeByName([
88
-            'Animation',
89
-            'Loop',
90
-            'Animate',
91
-            'ThumbnailNav',
92
-            'SliderControlNav',
93
-            'SliderDirectionNav',
94
-            'CarouselControlNav',
95
-            'CarouselDirectionNav',
96
-            'CarouselThumbnailCt',
97
-            'FlexSliderSpeed',
98
-            'Slides',
99
-        ]);
82
+	/**
83
+	 * @param FieldList $fields
84
+	 */
85
+	public function updateCMSFields(FieldList $fields)
86
+	{
87
+		$fields->removeByName([
88
+			'Animation',
89
+			'Loop',
90
+			'Animate',
91
+			'ThumbnailNav',
92
+			'SliderControlNav',
93
+			'SliderDirectionNav',
94
+			'CarouselControlNav',
95
+			'CarouselDirectionNav',
96
+			'CarouselThumbnailCt',
97
+			'FlexSliderSpeed',
98
+			'Slides',
99
+		]);
100 100
 
101
-        // Slides
102
-        if ($this->owner->ID) {
103
-            $config = GridFieldConfig_RecordEditor::create();
104
-            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
105
-            $config->removeComponentsByType([
106
-                GridFieldAddExistingAutocompleter::class,
107
-                GridFieldDeleteAction::class,
108
-            ]);
109
-            $SlidesField = GridField::create(
110
-                'Slides',
111
-                _t(__CLASS__ . '.SLIDES', 'Slides'),
112
-                $this->owner->Slides()->sort('SortOrder'),
113
-                $config
114
-            );
101
+		// Slides
102
+		if ($this->owner->ID) {
103
+			$config = GridFieldConfig_RecordEditor::create();
104
+			$config->addComponent(new GridFieldOrderableRows('SortOrder'));
105
+			$config->removeComponentsByType([
106
+				GridFieldAddExistingAutocompleter::class,
107
+				GridFieldDeleteAction::class,
108
+			]);
109
+			$SlidesField = GridField::create(
110
+				'Slides',
111
+				_t(__CLASS__ . '.SLIDES', 'Slides'),
112
+				$this->owner->Slides()->sort('SortOrder'),
113
+				$config
114
+			);
115 115
 
116
-            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
116
+			$slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
117 117
 
118
-            $animations = [];
119
-            $animationOptions = $this->owner->dbObject('Animation')->getEnum();
120
-            foreach ($animationOptions as $value) {
121
-                $animations[$value] = _t(__CLASS__ . ".$value", $value);
122
-            }
118
+			$animations = [];
119
+			$animationOptions = $this->owner->dbObject('Animation')->getEnum();
120
+			foreach ($animationOptions as $value) {
121
+				$animations[$value] = _t(__CLASS__ . ".$value", $value);
122
+			}
123 123
 
124
-            $fields->addFieldsToTab("Root.{$slideTitle}", [
125
-                $SlidesField,
126
-                ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
127
-                    DropdownField::create(
128
-                        'Animation',
129
-                        _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
130
-                        $animations
131
-                    ),
132
-                    CheckboxField::create(
133
-                        'Animate',
134
-                        _t(__CLASS__ . '.ANIMATE', 'Animate automatically')
135
-                    ),
136
-                    CheckboxField::create(
137
-                        'Loop',
138
-                        _t(__CLASS__ . '.LOOP', 'Loop the carousel')
139
-                    ),
140
-                    CheckboxField::create(
141
-                        'SliderControlNav',
142
-                        _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
143
-                    ),
144
-                    CheckboxField::create(
145
-                        'SliderDirectionNav',
146
-                        _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
147
-                    ),
148
-                    CheckboxField::create(
149
-                        'ThumbnailNav',
150
-                        _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
151
-                    ),
152
-                    //DisplayLogicWrapper::create(
153
-                    CheckboxField::create(
154
-                        'CarouselControlNav',
155
-                        _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156
-                    ),
157
-                    CheckboxField::create(
158
-                        'CarouselDirectionNav',
159
-                        _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160
-                    ),
161
-                    NumericField::create(
162
-                        'CarouselThumbnailCt',
163
-                        _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164
-                    ),
165
-                    NumericField::create(
166
-                        'FlexSliderSpeed',
167
-                        _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
168
-                    )
169
-                        ->setDescription('In Seconds')
170
-                        ->setScale(2),
171
-                ]),
172
-            ]);
173
-        }
174
-    }
124
+			$fields->addFieldsToTab("Root.{$slideTitle}", [
125
+				$SlidesField,
126
+				ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
127
+					DropdownField::create(
128
+						'Animation',
129
+						_t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
130
+						$animations
131
+					),
132
+					CheckboxField::create(
133
+						'Animate',
134
+						_t(__CLASS__ . '.ANIMATE', 'Animate automatically')
135
+					),
136
+					CheckboxField::create(
137
+						'Loop',
138
+						_t(__CLASS__ . '.LOOP', 'Loop the carousel')
139
+					),
140
+					CheckboxField::create(
141
+						'SliderControlNav',
142
+						_t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
143
+					),
144
+					CheckboxField::create(
145
+						'SliderDirectionNav',
146
+						_t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
147
+					),
148
+					CheckboxField::create(
149
+						'ThumbnailNav',
150
+						_t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
151
+					),
152
+					//DisplayLogicWrapper::create(
153
+					CheckboxField::create(
154
+						'CarouselControlNav',
155
+						_t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156
+					),
157
+					CheckboxField::create(
158
+						'CarouselDirectionNav',
159
+						_t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160
+					),
161
+					NumericField::create(
162
+						'CarouselThumbnailCt',
163
+						_t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164
+					),
165
+					NumericField::create(
166
+						'FlexSliderSpeed',
167
+						_t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
168
+					)
169
+						->setDescription('In Seconds')
170
+						->setScale(2),
171
+				]),
172
+			]);
173
+		}
174
+	}
175 175
 
176
-    /**
177
-     * @return mixed
178
-     */
179
-    public function getSlideShow()
180
-    {
181
-        $owner = $this->owner;
176
+	/**
177
+	 * @return mixed
178
+	 */
179
+	public function getSlideShow()
180
+	{
181
+		$owner = $this->owner;
182 182
 
183
-        if (!($owner instanceof SiteTree)) {
184
-            $this->getCustomScript();
185
-        }
183
+		if (!($owner instanceof SiteTree)) {
184
+			$this->getCustomScript();
185
+		}
186 186
 
187
-        return $this->owner->Slides()->sort('SortOrder');
188
-    }
187
+		return $this->owner->Slides()->sort('SortOrder');
188
+	}
189 189
 
190
-    /**
191
-     * add requirements to PageController init()
192
-     */
193
-    public function contentcontrollerInit()
194
-    {
195
-        // only call custom script if page has Slides and DataExtension
196
-        if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
197
-            if ($this->owner->getSlideShow()->exists()) {
198
-                $this->getCustomScript();
199
-            }
200
-        }
201
-    }
190
+	/**
191
+	 * add requirements to PageController init()
192
+	 */
193
+	public function contentcontrollerInit()
194
+	{
195
+		// only call custom script if page has Slides and DataExtension
196
+		if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
197
+			if ($this->owner->getSlideShow()->exists()) {
198
+				$this->getCustomScript();
199
+			}
200
+		}
201
+	}
202 202
 
203
-    /**
204
-     *
205
-     */
206
-    public function getCustomScript()
207
-    {
208
-        // Flexslider options
209
-        $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
203
+	/**
204
+	 *
205
+	 */
206
+	public function getCustomScript()
207
+	{
208
+		// Flexslider options
209
+		$sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
210 210
 
211
-        $before = $this->owner->hasMethod('flexSliderBeforeAction')
212
-            ? $this->owner->flexSliderBeforeAction()
213
-            : 'function(){}';
211
+		$before = $this->owner->hasMethod('flexSliderBeforeAction')
212
+			? $this->owner->flexSliderBeforeAction()
213
+			: 'function(){}';
214 214
 
215
-        $after = $this->owner->hasMethod('flexSliderAfterAction')
216
-            ? $this->owner->flexSliderAfterAction()
217
-            : 'function(){}';
215
+		$after = $this->owner->hasMethod('flexSliderAfterAction')
216
+			? $this->owner->flexSliderAfterAction()
217
+			: 'function(){}';
218 218
 
219
-        $speed = $this->getSlideshowSpeed();
219
+		$speed = $this->getSlideshowSpeed();
220 220
 
221
-        Requirements::customScript(
222
-            "(function($) {
221
+		Requirements::customScript(
222
+			"(function($) {
223 223
                 $(document).ready(function(){
224 224
                     jQuery('.flexslider').each(function(index){
225 225
 					 
@@ -265,39 +265,39 @@  discard block
 block discarded – undo
265 265
                     })
266 266
                 });
267 267
             }(jQuery));'
268
-        );
269
-    }
268
+		);
269
+	}
270 270
 
271
-    /**
272
-     * @return int
273
-     */
274
-    public function getSlideshowSpeed()
275
-    {
276
-        $speed = $this->owner->FlexSliderSpeed > 0
277
-            ? $this->owner->FlexSliderSpeed
278
-            : $this->getDefaultSpeed();
271
+	/**
272
+	 * @return int
273
+	 */
274
+	public function getSlideshowSpeed()
275
+	{
276
+		$speed = $this->owner->FlexSliderSpeed > 0
277
+			? $this->owner->FlexSliderSpeed
278
+			: $this->getDefaultSpeed();
279 279
 
280
-        return $speed * 1000;
281
-    }
280
+		return $speed * 1000;
281
+	}
282 282
 
283
-    /**
284
-     * @return mixed
285
-     */
286
-    protected function getDefaultSpeed()
287
-    {
288
-        return $this->owner->config()->get('flex_slider_speed')
289
-            ?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
290
-    }
283
+	/**
284
+	 * @return mixed
285
+	 */
286
+	protected function getDefaultSpeed()
287
+	{
288
+		return $this->owner->config()->get('flex_slider_speed')
289
+			?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
290
+	}
291 291
 
292
-    /**
293
-     *
294
-     */
295
-    public function onBeforeWrite()
296
-    {
297
-        parent::onBeforeWrite();
292
+	/**
293
+	 *
294
+	 */
295
+	public function onBeforeWrite()
296
+	{
297
+		parent::onBeforeWrite();
298 298
 
299
-        if (!$this->owner->CarouselThumbnailCt) {
300
-            $this->owner->CarouselThumbnailCt = 6;
301
-        }
302
-    }
299
+		if (!$this->owner->CarouselThumbnailCt) {
300
+			$this->owner->CarouselThumbnailCt = 6;
301
+		}
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -108,63 +108,63 @@  discard block
 block discarded – undo
108 108
             ]);
109 109
             $SlidesField = GridField::create(
110 110
                 'Slides',
111
-                _t(__CLASS__ . '.SLIDES', 'Slides'),
111
+                _t(__CLASS__.'.SLIDES', 'Slides'),
112 112
                 $this->owner->Slides()->sort('SortOrder'),
113 113
                 $config
114 114
             );
115 115
 
116
-            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
116
+            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__.'.SLIDES', 'Slides');
117 117
 
118 118
             $animations = [];
119 119
             $animationOptions = $this->owner->dbObject('Animation')->getEnum();
120 120
             foreach ($animationOptions as $value) {
121
-                $animations[$value] = _t(__CLASS__ . ".$value", $value);
121
+                $animations[$value] = _t(__CLASS__.".$value", $value);
122 122
             }
123 123
 
124 124
             $fields->addFieldsToTab("Root.{$slideTitle}", [
125 125
                 $SlidesField,
126
-                ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
126
+                ToggleCompositeField::create('ConfigHD', _t(__CLASS__.'.SettingsLabel', 'Slider Settings'), [
127 127
                     DropdownField::create(
128 128
                         'Animation',
129
-                        _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
129
+                        _t(__CLASS__.'.ANIMATION_OPTION', 'Animation option'),
130 130
                         $animations
131 131
                     ),
132 132
                     CheckboxField::create(
133 133
                         'Animate',
134
-                        _t(__CLASS__ . '.ANIMATE', 'Animate automatically')
134
+                        _t(__CLASS__.'.ANIMATE', 'Animate automatically')
135 135
                     ),
136 136
                     CheckboxField::create(
137 137
                         'Loop',
138
-                        _t(__CLASS__ . '.LOOP', 'Loop the carousel')
138
+                        _t(__CLASS__.'.LOOP', 'Loop the carousel')
139 139
                     ),
140 140
                     CheckboxField::create(
141 141
                         'SliderControlNav',
142
-                        _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
142
+                        _t(__CLASS__.'.CONTROL_NAV', 'Show ControlNav')
143 143
                     ),
144 144
                     CheckboxField::create(
145 145
                         'SliderDirectionNav',
146
-                        _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
146
+                        _t(__CLASS__.'.DIRECTION_NAV', 'Show DirectionNav')
147 147
                     ),
148 148
                     CheckboxField::create(
149 149
                         'ThumbnailNav',
150
-                        _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
150
+                        _t(__CLASS__.'.THUMBNAIL_NAV', 'Thumbnail Navigation')
151 151
                     ),
152 152
                     //DisplayLogicWrapper::create(
153 153
                     CheckboxField::create(
154 154
                         'CarouselControlNav',
155
-                        _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
155
+                        _t(__CLASS__.'.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156 156
                     ),
157 157
                     CheckboxField::create(
158 158
                         'CarouselDirectionNav',
159
-                        _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
159
+                        _t(__CLASS__.'.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160 160
                     ),
161 161
                     NumericField::create(
162 162
                         'CarouselThumbnailCt',
163
-                        _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
163
+                        _t(__CLASS__.'.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164 164
                     ),
165 165
                     NumericField::create(
166 166
                         'FlexSliderSpeed',
167
-                        _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
167
+                        _t(__CLASS__.'.SLIDER_SPEED', 'Slider Speed')
168 168
                     )
169 169
                         ->setDescription('In Seconds')
170 170
                         ->setScale(2),
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     public function getCustomScript()
207 207
     {
208 208
         // Flexslider options
209
-        $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
209
+        $sync = ($this->owner->ThumbnailNav==true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
210 210
 
211 211
         $before = $this->owner->hasMethod('flexSliderBeforeAction')
212 212
             ? $this->owner->flexSliderBeforeAction()
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
 					 
226 226
                          if(jQuery('.fs-carousel').eq(index).length) {
227 227
                              jQuery('.fs-carousel').eq(index).flexslider({
228
-                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ",
228
+                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean().",
229 229
                                 animation: 'slide',
230
-                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean() . ",
231
-                                controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean() . ", 
232
-                                directionNav: " . $this->owner->obj('CarouselDirectionNav')->NiceAsBoolean() . ",
230
+                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean().",
231
+                                controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean().", 
232
+                                directionNav: " . $this->owner->obj('CarouselDirectionNav')->NiceAsBoolean().",
233 233
                                 prevText: '',
234 234
                                 nextText: '',
235 235
                                 pausePlay: false,
236 236
                                 asNavFor: '.flexslider:eq('+index+')',
237
-                                minItems: " . $this->owner->obj('CarouselThumbnailCt') . ",
238
-                                maxItems: " . $this->owner->obj('CarouselThumbnailCt') . ",
239
-                                move: " . $this->owner->obj('CarouselThumbnailCt') . ",
237
+                                minItems: " . $this->owner->obj('CarouselThumbnailCt').",
238
+                                maxItems: " . $this->owner->obj('CarouselThumbnailCt').",
239
+                                move: " . $this->owner->obj('CarouselThumbnailCt').",
240 240
                                 itemWidth: 100,
241 241
                                 itemMargin: 10
242 242
                               });
@@ -244,22 +244,22 @@  discard block
 block discarded – undo
244 244
  
245 245
                         if(jQuery('.flexslider').eq(index).length){
246 246
                             jQuery('.flexslider').eq(index).flexslider({
247
-                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ",
248
-                                animation: '" . $this->owner->Animation . "',
249
-                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean() . ",
250
-                                controlNav: " . $this->owner->obj('SliderControlNav')->NiceAsBoolean() . ",
251
-                                directionNav: " . $this->owner->obj('SliderDirectionNav')->NiceAsBoolean() . ",
247
+                                slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean().",
248
+                                animation: '" . $this->owner->Animation."',
249
+                                animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean().",
250
+                                controlNav: " . $this->owner->obj('SliderControlNav')->NiceAsBoolean().",
251
+                                directionNav: " . $this->owner->obj('SliderDirectionNav')->NiceAsBoolean().",
252 252
                                 prevText: '',
253 253
                                 nextText: '',
254 254
                                 pauseOnAction: true,
255 255
                                 pauseOnHover: true,
256
-                                " . $sync . "
256
+                                " . $sync."
257 257
                                 start: function(slider){
258 258
                                   $('body').removeClass('loading');
259 259
                                 },
260
-                                before: " . $before . ',
261
-                                after: ' . $after . ',
262
-                                slideshowSpeed: ' . $speed . ' 
260
+                                before: " . $before.',
261
+                                after: ' . $after.',
262
+                                slideshowSpeed: ' . $speed.' 
263 263
                             });
264 264
                         }
265 265
                     })
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.