|
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
|
|
|
* @return string |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $singular_name = 'Features Element'; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $plural_name = 'Features Elements'; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
private static $table_name = 'ElementFeatures'; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
private static $db = [ |
|
|
|
|
|
|
45
|
|
|
'Content' => 'HTMLText', |
|
46
|
|
|
'Alternate' => 'Boolean', |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $has_many = [ |
|
|
|
|
|
|
53
|
|
|
'Features' => FeatureObject::class, |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be |
|
58
|
|
|
* clickable and a GridFieldDetailForm will be used. |
|
59
|
|
|
* |
|
60
|
|
|
* @config |
|
61
|
|
|
* @var bool |
|
62
|
|
|
*/ |
|
63
|
|
|
private static $inline_editable = false; |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return \SilverStripe\Forms\FieldList |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getCMSFields() |
|
69
|
|
|
{ |
|
70
|
1 |
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
71
|
1 |
|
$fields->dataFieldByName('Content') |
|
72
|
1 |
|
->setRows(8); |
|
73
|
1 |
|
$fields->dataFieldByName('Alternate')->setTitle('Alternate images and text'); |
|
74
|
|
|
|
|
75
|
1 |
|
if ($this->ID) { |
|
76
|
|
|
// Features |
|
77
|
1 |
|
$features = $fields->dataFieldByName('Features'); |
|
78
|
1 |
|
$config = $features->getConfig(); |
|
79
|
1 |
|
$config->addComponent(new GridFieldOrderableRows()); |
|
80
|
1 |
|
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
81
|
1 |
|
$config->removeComponentsByType(GridFieldDeleteAction::class); |
|
82
|
|
|
} |
|
83
|
1 |
|
}); |
|
84
|
|
|
|
|
85
|
1 |
|
return parent::getCMSFields(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return mixed |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function getFeaturesList() |
|
92
|
|
|
{ |
|
93
|
1 |
|
return $this->Features()->sort('Sort'); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return DBHTMLText |
|
98
|
|
|
*/ |
|
99
|
1 |
|
public function getSummary() |
|
100
|
|
|
{ |
|
101
|
1 |
|
if ($this->Features()->count() == 1) { |
|
102
|
|
|
$feature = 'feature'; |
|
103
|
|
|
} else { |
|
104
|
|
|
$feature = 'features'; |
|
105
|
|
|
} |
|
106
|
|
|
return DBField::create_field('HTMLText', $this->Features()->count() . ' ' . $feature)->Summary(20); |
|
107
|
1 |
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
/** |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function provideBlockSchema() |
|
113
|
|
|
{ |
|
114
|
|
|
$blockSchema = parent::provideBlockSchema(); |
|
115
|
|
|
$blockSchema['content'] = $this->getSummary(); |
|
116
|
|
|
return $blockSchema; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getType() |
|
123
|
|
|
{ |
|
124
|
|
|
return _t(__CLASS__.'.BlockType', 'Features'); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|