silverstripe-carousel 

silverstripe-carousel Commit Details

Date:2016-02-19 15:37:06 (4 years 4 months ago)
Author:Nicola Fontana
Branch:dev, master
Commit:ea62606ec8f6fb3bd5a9b9569af76f594dd01b03
Parents: 576cd9f08e4a83238dc31e7e457fbf0686f2d02e
Message:Add developer documentation

Changes:
Mcode/CarouselPage.php (11 diffs)

File differences

code/CarouselPage.php
11
22
3
4
5
6
7
38
49
510
11
12
613
714
815
......
2330
2431
2532
33
34
35
36
37
38
39
40
2641
2742
2843
......
4257
4358
4459
60
61
4562
4663
4764
65
66
67
68
69
70
71
4872
4973
5074
......
5680
5781
5882
83
84
5985
6086
6187
......
7298
7399
74100
101
102
103
104
105
75106
76107
77108
......
104135
105136
106137
138
139
107140
108141
109142
......
114147
115148
116149
117
118
150
151
119152
120153
121154
155
156
157
158
159
160
161
162
163
122164
123165
124166
......
145187
146188
147189
190
191
192
193
194
195
196
197
148198
149199
150200
......
163213
164214
165215
216
217
218
219
220
221
222
223
224
166225
167226
168227
......
174233
175234
176235
236
177237
178238
179
239
240
241
242
180243
181244
182245
......
193256
194257
195258
259
260
261
262
263
196264
197265
198266
<?php
/**
* Provide additional methods specially crafted for carousels.
*
* @package silverstripe-carousel
*/
class CarouselImageExtension extends DataExtension
{
/**
* Generate a scaled image suitable for a carousel.
*
* If $width and $height are greater than 0, it is equivalent to
* Image_Backend::croppedResize().
*
return $this->owner->getFormattedImage('MaybeCroppedImage', $width, $height);
}
/**
* Low level function for CarouselImageExtension::MaybeCroppedImage().
*
* @param Image_Backend $backend
* @param integer $width
* @param integer $height
* @return Image_Backend
*/
public function generateMaybeCroppedImage(Image_Backend $backend, $width, $height)
{
if ($width > 0 && $height > 0) {
* 'File' table with the WYSIWYG editor. That field is TEXT, hence just
* using HtmlEditorField will result in an error when the 'saveInto'
* method is called.
*
* @package silverstripe-carousel
*/
class CarouselCaptionField extends HtmlEditorField
{
/**
* Override the default constructor to have saner settings.
*
* @param string $name The internal field name, passed to forms.
* @param string $title The human-readable field label.
* @param mixed $value The value of the field.
*/
public function __construct($name, $title = null, $value = '')
{
parent::__construct($name, $title, $value);
/**
* Implementation directly borrowed from HtmlEditorField
* without the blocking or useless code.
*
* @param DataObjectInterface $record
*/
public function saveInto(DataObjectInterface $record)
{
}
}
/**
* Basic page type owning a carousel.
*
* @package silverstripe-carousel
*/
class CarouselPage extends Page
{
private static $icon = 'carousel/img/carousel.png';
* `Carousel` after.
*
* If no valid folders are found, `false` is returned.
*
* @return string|false
*/
protected function getClassFolder()
{
}
}
// false is the proper value to set in setFolderName()
// to get the default folder (usually 'Uploads').
// Why false? Because false is the proper value to set in
// setFolderName() to get the default folder (i.e. 'Uploads').
return false;
}
/**
* Add the "Images" tab to the content form of the page.
*
* The images are linked to the page with a many-many relationship,
* so if an image is shared among different carousels there is no
* need to upload it multiple times.
*
* @return FieldList
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();
return $fields;
}
/**
* Add carousel related fields to the page settings.
*
* Every CarouselPage instance can have its own settings, that is
* different pages can own carousels of different sizes.
*
* @return FieldList
*/
public function getSettingsFields()
{
$fields = parent::getSettingsFields();
return $fields;
}
/**
* Ensure ThumbnailWidth and ThumbnailHeight are valorized.
*
* Although width and height for the images in the carousel can be
* omitted (see CarouselImageExtension::MaybeCroppedImage() for
* algorithm details) the thumbnail extents must be defined.
*
* @return Validator
*/
public function getCMSValidator()
{
return RequiredFields::create(
/**
* Out of the box support for silverstripe/silverstripe-translatable.
*
* Duplicate the image list whenever a new translation is created.
* It the translatable module is not used, this will simply be a
* dead method.
*/
*
* @param boolean $save Whether the new page should be saved to the
* database.
*/
public function onTranslatableCreate($save)
{
// Chain up the parent method, if it exists
}
}
/**
* Controller for CarouselPage.
*
* @package silverstripe-carousel
*/
class CarouselPage_Controller extends Page_Controller
{
/**

Archive Download the corresponding diff file