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
|
|
|
private static $description = 'HTML text block'; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
private static $styles = []; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
*/ |
34
|
|
|
public function getCMSFields() |
35
|
|
|
{ |
36
|
|
|
$styles = $this->config()->get('styles'); |
37
|
|
|
|
38
|
|
|
if (count($styles) > 0) { |
39
|
|
|
$this->beforeUpdateCMSFields(function ($fields) use ($styles) { |
40
|
|
|
$fields->addFieldsToTab('Root.Main', new HtmlEditorField('HTML', _t(__CLASS__.'.CONTENT', 'Content'))); |
41
|
|
|
$fields->addFieldsToTab('Root.Main', $styles = new DropdownField('Style', _t(__CLASS__.'.STYLE', 'Style'), $styles)); |
42
|
|
|
$styles->setEmptyString(_t(__CLASS__.'.CUSTOM_STYLES', 'Select a custom style..')); |
43
|
|
|
}); |
44
|
|
|
} else { |
45
|
|
|
$this->beforeUpdateCMSFields(function ($fields) { |
46
|
|
|
$fields->removeByName('Style'); |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$fields = parent::getCMSFields(); |
51
|
|
|
|
52
|
|
|
if ($this->hasExtension('VersionViewerDataObject')) { |
53
|
|
|
$fields = $this->addVersionViewer($fields, $this); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $fields; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getCssStyle() |
63
|
|
|
{ |
64
|
|
|
$styles = $this->config()->get('styles'); |
65
|
|
|
$style = $this->Style; |
|
|
|
|
66
|
|
|
|
67
|
|
|
if (isset($styles[$style])) { |
68
|
|
|
return strtolower($styles[$style]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getSummary() |
73
|
|
|
{ |
74
|
|
|
return DBField::create_field('HTMLText', $this->HTML)->Summary(20); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getType() |
78
|
|
|
{ |
79
|
|
|
return _t(__CLASS__ . '.BlockType', 'Content'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.