|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\Elements\Features\Elements; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
|
6
|
|
|
use Dynamic\Elements\Features\Model\FeatureObject; |
|
7
|
|
|
use SilverStripe\Forms\FieldList; |
|
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
|
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
|
10
|
|
|
use SilverStripe\ORM\FieldType\DBField; |
|
11
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText; |
|
12
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class PageSectionBlock. |
|
16
|
|
|
* |
|
17
|
|
|
* @method HasManyList $Features |
|
18
|
|
|
*/ |
|
19
|
|
|
class ElementFeatures extends BaseElement |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $icon = 'font-icon-block-banner'; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $table_name = 'ElementFeatures'; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $db = [ |
|
|
|
|
|
|
35
|
|
|
'Content' => 'HTMLText', |
|
36
|
|
|
'Alternate' => 'Boolean', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private static $has_many = [ |
|
|
|
|
|
|
43
|
|
|
'Features' => FeatureObject::class, |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be |
|
48
|
|
|
* clickable and a GridFieldDetailForm will be used. |
|
49
|
|
|
* |
|
50
|
|
|
* @config |
|
51
|
|
|
* @var bool |
|
52
|
|
|
*/ |
|
53
|
|
|
private static $inline_editable = false; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param bool $includerelations |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function fieldLabels($includerelations = true) |
|
60
|
|
|
{ |
|
61
|
1 |
|
$labels = parent::fieldLabels($includerelations); |
|
62
|
|
|
|
|
63
|
1 |
|
$labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Description'); |
|
64
|
1 |
|
$labels['Alternate'] = _t(__CLASS__ . '.AlternateLabel', 'Alternate'); |
|
65
|
1 |
|
$labels['Features'] = _t(__CLASS__ . '.FeaturesLabel', 'Features'); |
|
66
|
|
|
|
|
67
|
1 |
|
return $labels; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return \SilverStripe\Forms\FieldList |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getCMSFields() |
|
74
|
|
|
{ |
|
75
|
1 |
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
76
|
1 |
|
$fields->dataFieldByName('Content') |
|
77
|
1 |
|
->setRows(8); |
|
78
|
1 |
|
$fields->dataFieldByName('Alternate') |
|
79
|
1 |
|
->setDescription(_t( |
|
80
|
1 |
|
__CLASS__ . '.AlternateDescription', |
|
81
|
1 |
|
'Alternate image and text alignment' |
|
82
|
|
|
)); |
|
83
|
|
|
|
|
84
|
1 |
|
if ($this->ID) { |
|
85
|
|
|
// Features |
|
86
|
1 |
|
$features = $fields->dataFieldByName('Features'); |
|
87
|
1 |
|
$fields->removeByName('Features'); |
|
88
|
|
|
|
|
89
|
1 |
|
$config = $features->getConfig(); |
|
90
|
|
|
$config |
|
91
|
1 |
|
->addComponent(new GridFieldOrderableRows()) |
|
92
|
1 |
|
->removeComponentsByType([ |
|
93
|
1 |
|
GridFieldAddExistingAutocompleter::class, |
|
94
|
|
|
GridFieldDeleteAction::class |
|
95
|
|
|
]); |
|
96
|
|
|
|
|
97
|
1 |
|
$fields->addFieldToTab('Root.Main', $features); |
|
98
|
|
|
} |
|
99
|
1 |
|
}); |
|
100
|
|
|
|
|
101
|
1 |
|
return parent::getCMSFields(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return mixed |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function getFeaturesList() |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->Features()->sort('Sort'); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return DBHTMLText |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function getSummary() |
|
116
|
|
|
{ |
|
117
|
1 |
|
$count = $this->Features()->count(); |
|
118
|
1 |
|
$label = _t( |
|
119
|
1 |
|
FeatureObject::class . '.PLURALS', |
|
120
|
1 |
|
'A Feature|{count} Features', |
|
121
|
1 |
|
[ 'count' => $count ] |
|
122
|
|
|
); |
|
123
|
1 |
|
return DBField::create_field('HTMLText', $label)->Summary(20); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return array |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function provideBlockSchema() |
|
130
|
|
|
{ |
|
131
|
|
|
$blockSchema = parent::provideBlockSchema(); |
|
132
|
|
|
$blockSchema['content'] = $this->getSummary(); |
|
133
|
|
|
return $blockSchema; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function getType() |
|
140
|
|
|
{ |
|
141
|
1 |
|
return _t(__CLASS__.'.BlockType', 'Features'); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|