1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package elemental |
5
|
|
|
*/ |
6
|
|
|
class BaseElement extends Widget |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var array $db |
10
|
|
|
*/ |
11
|
|
|
private static $db = array( |
|
|
|
|
12
|
|
|
'ExtraClass' => 'Varchar(255)', |
13
|
|
|
'HideTitle' => 'Boolean' |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array $has_one |
18
|
|
|
*/ |
19
|
|
|
private static $has_one = array( |
|
|
|
|
20
|
|
|
'List' => 'ElementList' // optional. |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array $has_many |
25
|
|
|
*/ |
26
|
|
|
private static $has_many = array( |
|
|
|
|
27
|
|
|
'VirtualClones' => 'ElementVirtualLinked' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private static $title = "Content Block"; |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private static $singular_name = 'Content Block'; |
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private static $summary_fields = array( |
|
|
|
|
44
|
|
|
'ID' => 'ID', |
45
|
|
|
'Title' => 'Title', |
46
|
|
|
'ElementType' => 'Type' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var boolean |
51
|
|
|
*/ |
52
|
|
|
protected $enable_title_in_template = false; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function getCMSFields() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$fields = $this->scaffoldFormFields(array( |
58
|
|
|
'includeRelations' => ($this->ID > 0), |
59
|
|
|
'tabbed' => true, |
60
|
|
|
'ajaxSafe' => true |
61
|
|
|
)); |
62
|
|
|
|
63
|
|
|
$fields->insertAfter(new ReadonlyField('ClassNameTranslated', _t('BaseElement.TYPE', 'Type'), $this->i18n_singular_name()), 'Title'); |
|
|
|
|
64
|
|
|
$fields->removeByName('ListID'); |
65
|
|
|
$fields->removeByName('ParentID'); |
66
|
|
|
$fields->removeByName('Sort'); |
67
|
|
|
$fields->removeByName('ExtraClass'); |
68
|
|
|
|
69
|
|
|
if (!$this->enable_title_in_template) { |
70
|
|
|
$fields->removeByName('HideTitle'); |
71
|
|
|
$title = $fields->fieldByName('Root.Main.Title'); |
72
|
|
|
|
73
|
|
|
if ($title) { |
74
|
|
|
$title->setRightTitle('For reference only. Does not appear in the template.'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$fields->addFieldToTab('Root.Settings', new TextField('ExtraClass', 'Extra CSS Classes to add')); |
79
|
|
|
|
80
|
|
|
if (!is_a($this, 'ElementList')) { |
81
|
|
|
$lists = ElementList::get()->filter('ParentID', $this->ParentID); |
|
|
|
|
82
|
|
|
|
83
|
|
|
if ($lists->exists()) { |
84
|
|
|
$fields->addFieldToTab('Root.Main', |
85
|
|
|
$move = new DropdownField('MoveToListID', 'Move this to another list', $lists->map('ID', 'CMSTitle'), '') |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$move->setEmptyString('Select a list..'); |
89
|
|
|
$move->setHasEmptyDefault(true); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
if($virtual = $fields->dataFieldByName('VirtualClones')) { |
95
|
|
|
$tab = $fields->findOrMakeTab('Root.VirtualClones'); |
96
|
|
|
$tab->setTitle(_t('BaseElement.VIRTUALTABTITLE', 'Linked To')); |
97
|
|
|
|
98
|
|
|
$virtual |
|
|
|
|
99
|
|
|
->setTitle(_t('BaseElement.VIRTUALTABTITLE', 'Linked To')) |
100
|
|
|
->getConfig() |
101
|
|
|
->removeComponentsByType('GridFieldAddExistingAutocompleter') |
102
|
|
|
->removeComponentsByType('GridFieldAddNewButton'); |
103
|
|
|
|
104
|
|
|
$virtual->getConfig() |
|
|
|
|
105
|
|
|
->getComponentByType('GridFieldDataColumns') |
106
|
|
|
->setDisplayFields(array( |
107
|
|
|
'Parent.getOwnerPage.Title' => 'Title', |
108
|
|
|
'Parent.getOwnerPage.Link' => 'Link' |
109
|
|
|
)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->extend('updateCMSFields', $fields); |
113
|
|
|
|
114
|
|
|
if ($this->IsInDB()) { |
115
|
|
|
if ($this->isEndofLine('BaseElement') && $this->hasExtension('VersionViewerDataObject')) { |
116
|
|
|
$fields = $this->addVersionViewer($fields, $this); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $fields; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Version viewer must only be added at if this is the final getCMSFields for a class. |
125
|
|
|
* in order to avoid having to rename all fields from eg Root.Main to Root.Current.Main |
126
|
|
|
* To do this we test if getCMSFields is from the current class |
127
|
|
|
*/ |
128
|
|
|
public function isEndofLine($className) |
129
|
|
|
{ |
130
|
|
|
$methodFromClass = ClassInfo::has_method_from( |
131
|
|
|
$this->ClassName, 'getCMSFields', $className |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
if($methodFromClass) { |
135
|
|
|
return true; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function onBeforeWrite() |
141
|
|
|
{ |
142
|
|
|
parent::onBeforeWrite(); |
143
|
|
|
|
144
|
|
|
if (!$this->Sort) { |
|
|
|
|
145
|
|
|
$parentID = ($this->ParentID) ? $this->ParentID : 0; |
|
|
|
|
146
|
|
|
|
147
|
|
|
$this->Sort = DB::query("SELECT MAX(\"Sort\") + 1 FROM \"Widget\" WHERE \"ParentID\" = $parentID")->value(); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if ($this->MoveToListID) { |
|
|
|
|
151
|
|
|
$this->ListID = $this->MoveToListID; |
|
|
|
|
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function i18n_singular_name() |
156
|
|
|
{ |
157
|
|
|
return _t(__CLASS__, $this->config()->title); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function getElementType() |
161
|
|
|
{ |
162
|
|
|
return $this->i18n_singular_name(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
View Code Duplication |
public function getTitle() |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
if ($title = $this->getField('Title')) { |
168
|
|
|
return $title; |
169
|
|
|
} else { |
170
|
|
|
if (!$this->isInDb()) { |
171
|
|
|
return; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $this->config()->title; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
View Code Duplication |
public function getCMSTitle() |
|
|
|
|
179
|
|
|
{ |
180
|
|
|
if ($title = $this->getField('Title')) { |
181
|
|
|
return $this->config()->title . ': ' . $title; |
182
|
|
|
} else { |
183
|
|
|
if (!$this->isInDb()) { |
184
|
|
|
return; |
185
|
|
|
} |
186
|
|
|
return $this->config()->title; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function canView($member = null) |
191
|
|
|
{ |
192
|
|
|
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function canEdit($member = null) |
196
|
|
|
{ |
197
|
|
|
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function canDelete($member = null) |
201
|
|
|
{ |
202
|
|
|
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function canCreate($member = null) |
206
|
|
|
{ |
207
|
|
|
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function ControllerTop() |
211
|
|
|
{ |
212
|
|
|
return Controller::curr(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function getPage() |
216
|
|
|
{ |
217
|
|
|
$area = $this->Parent(); |
|
|
|
|
218
|
|
|
|
219
|
|
|
if ($area instanceof ElementalArea) { |
220
|
|
|
return $area->getOwnerPage(); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
return null; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Override the {@link Widget::forTemplate()} method so that holders are not rendered twice. The controller should |
228
|
|
|
* render with widget inside the |
229
|
|
|
* |
230
|
|
|
* @return HTML |
|
|
|
|
231
|
|
|
*/ |
232
|
|
|
public function forTemplate($holder = true) { |
233
|
|
|
return $this->renderWith($this->class); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @return string |
238
|
|
|
*/ |
239
|
|
|
public function getEditLink() { |
240
|
|
|
return Controller::join_links( |
241
|
|
|
Director::absoluteBaseURL(), |
242
|
|
|
'admin/elemental/BaseElement/EditForm/field/BaseElement/item', |
243
|
|
|
$this->ID, |
244
|
|
|
'edit' |
245
|
|
|
); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function onBeforeVersionedPublish() |
249
|
|
|
{ |
250
|
|
|
|
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.