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