1 | <?php |
||
2 | namespace DorsetDigital\Elements; |
||
3 | |||
4 | use DNADesign\Elemental\Models\BaseElement; |
||
5 | use SilverStripe\AssetAdmin\Forms\UploadField; |
||
6 | use SilverStripe\Assets\Image; |
||
7 | use SilverStripe\Forms\DropdownField; |
||
8 | use SilverStripe\Forms\HTMLEditor\HTMLEditorField; |
||
9 | use SilverStripe\Forms\TextField; |
||
10 | use SilverStripe\ORM\FieldType\DBField; |
||
11 | |||
12 | |||
13 | class ImageTextElement extends BaseElement |
||
14 | { |
||
15 | |||
16 | private static $singular_name = 'Text & Image Block'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
17 | private static $plural_name = 'Text & Image Blocks'; |
||
0 ignored issues
–
show
|
|||
18 | private static $description = 'Adds a block of text with accompanying image'; |
||
0 ignored issues
–
show
|
|||
19 | private static $table_name = 'DorsetDigital_Elements_ImageText'; |
||
0 ignored issues
–
show
|
|||
20 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
21 | 'Content' => 'HTMLText', |
||
0 ignored issues
–
show
|
|||
22 | 'ImagePosition' => 'Varchar(10)', |
||
0 ignored issues
–
show
|
|||
23 | 'ImageAlt' => 'Varchar(255)', |
||
0 ignored issues
–
show
|
|||
24 | 'ImageWidth' => 'Varchar(10)' |
||
0 ignored issues
–
show
|
|||
25 | ]; |
||
0 ignored issues
–
show
|
|||
26 | private static $many_many = [ |
||
0 ignored issues
–
show
|
|||
27 | 'Image' => Image::class |
||
0 ignored issues
–
show
|
|||
28 | ]; |
||
0 ignored issues
–
show
|
|||
29 | private static $owns = [ |
||
0 ignored issues
–
show
|
|||
30 | 'Image' |
||
31 | ]; |
||
0 ignored issues
–
show
|
|||
32 | private static $inline_editable = false; |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | private static $sizes = [ |
||
0 ignored issues
–
show
|
|||
35 | 'half' => '1/2 page width', |
||
0 ignored issues
–
show
|
|||
36 | 'third' => '1/3 page width', |
||
0 ignored issues
–
show
|
|||
37 | 'quarter' => '1/4 page width', |
||
0 ignored issues
–
show
|
|||
38 | 'sixth' => '1/6 page width' |
||
0 ignored issues
–
show
|
|||
39 | ]; |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | |||
42 | public function getCMSFields() |
||
0 ignored issues
–
show
This method is not in camel caps format.
This check looks for method names that are not written in camelCase. In camelCase names are written without any punctuation, the start of each new
word being marked by a capital letter. Thus the name
database connection seeker becomes ![]() |
|||
43 | { |
||
44 | $fields = parent::getCMSFields(); |
||
45 | $fields->addFieldsToTab('Root.Main', [ |
||
46 | HTMLEditorField::create('Content'), |
||
0 ignored issues
–
show
|
|||
47 | UploadField::create('Image') |
||
0 ignored issues
–
show
|
|||
48 | ->setAllowedFileCategories('image/supported') |
||
49 | ->setFolderName('pageimages') |
||
50 | ->setAllowedMaxFileNumber(1), |
||
51 | DropdownField::create('ImagePosition') |
||
0 ignored issues
–
show
|
|||
52 | ->setSource([ 'after' => 'After Content', 'before' => 'Before Content' ]), |
||
53 | TextField::create('ImageAlt')->setTitle('Alt text for the image'), |
||
0 ignored issues
–
show
|
|||
54 | DropdownField::create('ImageWidth') |
||
55 | ->setSource($this->config()->get('sizes')) |
||
56 | ->setDescription('Relative image size on larger screens. On smaller screens the image will flow before or after the text content, instead of sitting next to it.') |
||
0 ignored issues
–
show
|
|||
57 | ]); |
||
0 ignored issues
–
show
|
|||
58 | return $fields; |
||
59 | } |
||
0 ignored issues
–
show
|
|||
60 | |||
61 | public function getType() |
||
62 | { |
||
63 | return 'Image & Text'; |
||
64 | } |
||
65 | |||
66 | |||
67 | } |
||
68 |