1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ORM; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
6
|
|
|
use SilverStripe\Core\Extension; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\Forms\CompositeValidator; |
9
|
|
|
use SilverStripe\ORM\Queries\SQLSelect; |
10
|
|
|
use Exception; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* An extension that adds additional functionality to a {@link DataObject}. |
14
|
|
|
* |
15
|
|
|
* @property DataObject $owner |
16
|
|
|
*/ |
17
|
|
|
abstract class DataExtension extends Extension |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @deprecated 4.7.0 No longer used by internal code |
22
|
|
|
*/ |
23
|
|
|
public static function unload_extra_statics($class, $extension) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
throw new Exception('unload_extra_statics gone'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Hook for extension-specific validation. |
30
|
|
|
* |
31
|
|
|
* @param ValidationResult $validationResult Local validation result |
32
|
|
|
* @throws ValidationException |
33
|
|
|
*/ |
34
|
|
|
public function validate(ValidationResult $validationResult) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Edit the given query object to support queries for this extension |
40
|
|
|
* |
41
|
|
|
* @param SQLSelect $query Query to augment. |
42
|
|
|
* @param DataQuery $dataQuery Container DataQuery for this SQLSelect |
43
|
|
|
*/ |
44
|
|
|
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Update the database schema as required by this extension. |
50
|
|
|
* |
51
|
|
|
* When duplicating a table's structure, remember to duplicate the create options |
52
|
|
|
* as well. See {@link Versioned->augmentDatabase} for an example. |
53
|
|
|
*/ |
54
|
|
|
public function augmentDatabase() |
55
|
|
|
{ |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Augment a write-record request. |
60
|
|
|
* |
61
|
|
|
* @param array $manipulation Array of operations to augment. |
62
|
|
|
*/ |
63
|
|
|
public function augmentWrite(&$manipulation) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Extend the owner's onBeforeWrite() logic |
69
|
|
|
* |
70
|
|
|
* See {@link DataObject::onBeforeWrite()} for context. |
71
|
|
|
*/ |
72
|
|
|
public function onBeforeWrite() |
73
|
|
|
{ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Extend the owner's onAfterWrite() logic |
78
|
|
|
* |
79
|
|
|
* See {@link DataObject::onAfterWrite()} for context. |
80
|
|
|
*/ |
81
|
|
|
public function onAfterWrite() |
82
|
|
|
{ |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Extend the owner's onBeforeDelete() logic |
87
|
|
|
* |
88
|
|
|
* See {@link DataObject::onBeforeDelete()} for context. |
89
|
|
|
*/ |
90
|
|
|
public function onBeforeDelete() |
91
|
|
|
{ |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Extend the owner's onAfterDelete() logic |
96
|
|
|
* |
97
|
|
|
* See {@link DataObject::onAfterDelete()} for context. |
98
|
|
|
*/ |
99
|
|
|
public function onAfterDelete() |
100
|
|
|
{ |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Extend the owner's requireDefaultRecords() logic |
105
|
|
|
* |
106
|
|
|
* See {@link DataObject::requireDefaultRecords()} for context. |
107
|
|
|
*/ |
108
|
|
|
public function requireDefaultRecords() |
109
|
|
|
{ |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Extend the owner's populateDefaults() logic |
114
|
|
|
* |
115
|
|
|
* See {@link DataObject::populateDefaults()} for context. |
116
|
|
|
*/ |
117
|
|
|
public function populateDefaults() |
118
|
|
|
{ |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Extend the owner's onAfterBuild() logic |
123
|
|
|
* |
124
|
|
|
* See {@link DataObject::onAfterBuild()} for context. |
125
|
|
|
*/ |
126
|
|
|
public function onAfterBuild() |
127
|
|
|
{ |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Influence the owner's can() permission check value to be disallowed (false), |
132
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not |
133
|
|
|
* affect the outcome. |
134
|
|
|
* |
135
|
|
|
* See {@link DataObject::can()} and {@link DataObject::extendedCan()} for context. |
136
|
|
|
* |
137
|
|
|
* @param Member $member |
|
|
|
|
138
|
|
|
* @param array $context |
139
|
|
|
* @return bool|null |
140
|
|
|
*/ |
141
|
|
|
public function can($member) |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Influence the owner's canEdit() permission check value to be disallowed (false), |
147
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not |
148
|
|
|
* affect the outcome. |
149
|
|
|
* |
150
|
|
|
* See {@link DataObject::canEdit()} and {@link DataObject::extendedCan()} for context. |
151
|
|
|
* |
152
|
|
|
* @param Member $member |
153
|
|
|
* @param array $context |
154
|
|
|
* @return bool|null |
155
|
|
|
*/ |
156
|
|
|
public function canEdit($member) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Influence the owner's canDelete() permission check value to be disallowed (false), |
162
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not |
163
|
|
|
* affect the outcome. |
164
|
|
|
* |
165
|
|
|
* See {@link DataObject::canDelete()} and {@link DataObject::extendedCan()} for context. |
166
|
|
|
* |
167
|
|
|
* @param Member $member |
168
|
|
|
* @param array $context |
169
|
|
|
* @return bool|null |
170
|
|
|
*/ |
171
|
|
|
public function canDelete($member) |
|
|
|
|
172
|
|
|
{ |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Influence the owner's canCreate() permission check value to be disallowed (false), |
177
|
|
|
* allowed (true) if no other processed results are to disallow, or open (null) to not |
178
|
|
|
* affect the outcome. |
179
|
|
|
* |
180
|
|
|
* See {@link DataObject::canCreate()} and {@link DataObject::extendedCan()} for context. |
181
|
|
|
* |
182
|
|
|
* @param Member $member |
183
|
|
|
* @param array $context |
184
|
|
|
* @return bool|null |
185
|
|
|
*/ |
186
|
|
|
public function canCreate($member) |
|
|
|
|
187
|
|
|
{ |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Define extra database fields |
192
|
|
|
* |
193
|
|
|
* Return a map where the keys are db, has_one, etc, and the values are |
194
|
|
|
* additional fields/relations to be defined. |
195
|
|
|
* |
196
|
|
|
* @param string $class since this method might be called on the class directly |
197
|
|
|
* @param string $extension since this can help to extract parameters to help set indexes |
198
|
|
|
* @return array Returns a map where the keys are db, has_one, etc, and |
199
|
|
|
* the values are additional fields/relations to be defined. |
200
|
|
|
*/ |
201
|
|
|
public function extraStatics($class = null, $extension = null) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
return []; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* This function is used to provide modifications to the form in the CMS |
208
|
|
|
* by the extension. By default, no changes are made. {@link DataObject->getCMSFields()}. |
209
|
|
|
* |
210
|
|
|
* Please consider using {@link updateFormFields()} to globally add |
211
|
|
|
* formfields to the record. The method {@link updateCMSFields()} |
212
|
|
|
* should just be used to add or modify tabs, or fields which |
213
|
|
|
* are specific to the CMS-context. |
214
|
|
|
* |
215
|
|
|
* Caution: Use {@link FieldList->addFieldToTab()} to add fields. |
216
|
|
|
* |
217
|
|
|
* @param FieldList $fields FieldList with a contained TabSet |
218
|
|
|
*/ |
219
|
|
|
public function updateCMSFields(FieldList $fields) |
220
|
|
|
{ |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* This function is used to provide modifications to the Validators used on a DataObject. |
225
|
|
|
* |
226
|
|
|
* Caution: Use {@link CompositeValidator->addValidator()} to add Validators. |
227
|
|
|
* |
228
|
|
|
* @param CompositeValidator $compositeValidator |
229
|
|
|
*/ |
230
|
|
|
public function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void |
|
|
|
|
231
|
|
|
{ |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* This function is used to provide modifications to the form used |
236
|
|
|
* for front end forms. {@link DataObject->getFrontEndFields()} |
237
|
|
|
* |
238
|
|
|
* Caution: Use {@link FieldList->push()} to add fields. |
239
|
|
|
* |
240
|
|
|
* @param FieldList $fields FieldList without TabSet nesting |
241
|
|
|
*/ |
242
|
|
|
public function updateFrontEndFields(FieldList $fields) |
|
|
|
|
243
|
|
|
{ |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* This is used to provide modifications to the form actions |
248
|
|
|
* used in the CMS. {@link DataObject->getCMSActions()}. |
249
|
|
|
* |
250
|
|
|
* @param FieldList $actions FieldList |
251
|
|
|
*/ |
252
|
|
|
public function updateCMSActions(FieldList $actions) |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* this function is used to provide modifications to the summary fields in CMS |
258
|
|
|
* by the extension |
259
|
|
|
* By default, the summaryField() of its owner will merge more fields defined in the extension's |
260
|
|
|
* $extra_fields['summary_fields'] |
261
|
|
|
* |
262
|
|
|
* @param array $fields Array of field names |
263
|
|
|
*/ |
264
|
|
|
public function updateSummaryFields(&$fields) |
265
|
|
|
{ |
266
|
|
|
$summary_fields = Config::inst()->get(static::class, 'summary_fields'); |
267
|
|
|
if ($summary_fields) { |
268
|
|
|
// if summary_fields were passed in numeric array, |
269
|
|
|
// convert to an associative array |
270
|
|
|
if ($summary_fields && array_key_exists(0, $summary_fields)) { |
271
|
|
|
$summary_fields = array_combine(array_values($summary_fields), array_values($summary_fields)); |
272
|
|
|
} |
273
|
|
|
if ($summary_fields) { |
274
|
|
|
$fields = array_merge($fields, $summary_fields); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* this function is used to provide modifications to the fields labels in CMS |
281
|
|
|
* by the extension |
282
|
|
|
* By default, the fieldLabels() of its owner will merge more fields defined in the extension's |
283
|
|
|
* $extra_fields['field_labels'] |
284
|
|
|
* |
285
|
|
|
* @param array $labels Array of field labels |
286
|
|
|
*/ |
287
|
|
|
public function updateFieldLabels(&$labels) |
288
|
|
|
{ |
289
|
|
|
$field_labels = Config::inst()->get(static::class, 'field_labels'); |
290
|
|
|
if ($field_labels) { |
291
|
|
|
$labels = array_merge($labels, $field_labels); |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.