1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Models; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\HTMLEditor\HtmlEditorField; |
6
|
|
|
use SilverStripe\Forms\DropdownField; |
7
|
|
|
use SilverStripe\ORM\FieldType\DBField; |
8
|
|
|
|
9
|
|
|
class ElementContent extends BaseElement |
10
|
|
|
{ |
11
|
|
|
private static $icon = 'dnadesign/silverstripe-elemental:images/content.svg'; |
|
|
|
|
12
|
|
|
|
13
|
|
|
private static $db = [ |
|
|
|
|
14
|
|
|
'HTML' => 'HTMLText', |
15
|
|
|
'Style' => 'Varchar(255)' |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
private static $table_name = 'ElementContent'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private static $singular_name = 'content block'; |
|
|
|
|
21
|
|
|
|
22
|
|
|
private static $plural_name = 'content blocks'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private static $styles = []; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritDoc} |
31
|
|
|
*/ |
32
|
|
|
public function getCMSFields() |
33
|
|
|
{ |
34
|
|
|
$styles = $this->config()->get('styles'); |
35
|
|
|
|
36
|
|
|
if (count($styles) > 0) { |
37
|
|
|
$this->beforeUpdateCMSFields(function ($fields) use ($styles) { |
38
|
|
|
$fields->addFieldsToTab('Root.Main', new HtmlEditorField('HTML', _t(__CLASS__.'.CONTENT', 'Content'))); |
39
|
|
|
$fields->addFieldsToTab('Root.Main', $styles = new DropdownField('Style', _t(__CLASS__.'.STYLE', 'Style'), $styles)); |
40
|
|
|
$styles->setEmptyString(_t(__CLASS__.'.CUSTOM_STYLES', 'Select a custom style..')); |
41
|
|
|
}); |
42
|
|
|
} else { |
43
|
|
|
$this->beforeUpdateCMSFields(function ($fields) { |
44
|
|
|
$fields->removeByName('Style'); |
45
|
|
|
}); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$fields = parent::getCMSFields(); |
49
|
|
|
|
50
|
|
|
if ($this->hasExtension('VersionViewerDataObject')) { |
51
|
|
|
$fields = $this->addVersionViewer($fields, $this); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $fields; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getCssStyle() |
61
|
|
|
{ |
62
|
|
|
$styles = $this->config()->get('styles'); |
63
|
|
|
$style = $this->Style; |
|
|
|
|
64
|
|
|
|
65
|
|
|
if (isset($styles[$style])) { |
66
|
|
|
return strtolower($styles[$style]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return HTMLText |
|
|
|
|
72
|
|
|
*/ |
73
|
|
|
public function ElementSummary() |
74
|
|
|
{ |
75
|
|
|
return DBField::create_field('HTMLText', $this->HTML)->Summary(20); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getType() |
79
|
|
|
{ |
80
|
|
|
return _t(__CLASS__ . '.BlockType', 'Content'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.