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