|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) |
|
6
|
|
|
* Nathan Boiron <[email protected]> |
|
7
|
|
|
* Romain Canon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
11
|
|
|
* under the terms of the GNU General Public License, either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, see: |
|
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Core\Notification\TCA; |
|
19
|
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Backend\FormEngine\DataProvider\DefaultEventFromGet; |
|
21
|
|
|
use CuyZ\Notiz\Core\Notification\Service\NotificationTcaService; |
|
22
|
|
|
use CuyZ\Notiz\Core\Notification\TCA\Processor\EventConfigurationProcessor; |
|
23
|
|
|
use CuyZ\Notiz\Service\Traits\SelfInstantiateTrait; |
|
24
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
25
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
|
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
27
|
|
|
|
|
28
|
|
|
abstract class EntityTcaWriter implements SingletonInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use SelfInstantiateTrait; |
|
31
|
|
|
|
|
32
|
|
|
const NOTIFICATION_ENTITY = 'notificationEntity'; |
|
33
|
|
|
|
|
34
|
|
|
const LLL = 'LLL:EXT:notiz/Resources/Private/Language/Notification/Entity/Entity.xlf'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Contains the name of the TCA table. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $tableName; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var NotificationTcaService |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $service; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
private $data = []; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Manual injection for the TCA service depending on the entity type. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->service = GeneralUtility::makeInstance($this->getNotificationTcaServiceClass()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* This method must create the basic TCA configuration. It must fill at |
|
63
|
|
|
* least the `ctrl` and `columns` sections. |
|
64
|
|
|
* |
|
65
|
|
|
* Default TYPO3 columns are added automatically, so no need to add them. |
|
66
|
|
|
* Common notifications columns are also added automatically. |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
abstract protected function buildTcaArray(): array; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* This method builds a TCA array and returns it to be used in a |
|
74
|
|
|
* configuration file. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $tableName |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
final public function getTcaArray(string $tableName): array |
|
80
|
|
|
{ |
|
81
|
|
|
$this->tableName = $tableName; |
|
82
|
|
|
|
|
83
|
|
|
// Each sub-class starts to fill the array. |
|
84
|
|
|
$this->data = $this->buildTcaArray(); |
|
85
|
|
|
|
|
86
|
|
|
// Some columns are common for all notification types |
|
87
|
|
|
$this->addCommonColumns(); |
|
88
|
|
|
|
|
89
|
|
|
// The default columns are always the same. |
|
90
|
|
|
$this->addDefaultTypo3Columns(); |
|
91
|
|
|
|
|
92
|
|
|
return $this->data; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* This method returns the TCA service class for the current entity type. |
|
97
|
|
|
* You can override it to return a class extending `NotificationTcaService`. |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
abstract protected function getNotificationTcaServiceClass(): string; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Returns the title of the entity, can be a LLL reference. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
abstract protected function getEntityTitle(): string; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* This method returns the LLL string to use for the `channel` column. |
|
112
|
|
|
* |
|
113
|
|
|
* @return string |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function getChannelLabel(): string |
|
116
|
|
|
{ |
|
117
|
|
|
return self::LLL . ':field.channel'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return array |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function getDefaultCtrl(): array |
|
124
|
|
|
{ |
|
125
|
|
|
return [ |
|
126
|
|
|
'title' => $this->getEntityTitle(), |
|
127
|
|
|
|
|
128
|
|
|
'label' => 'title', |
|
129
|
|
|
'descriptionColumn' => 'description', |
|
130
|
|
|
'tstamp' => 'tstamp', |
|
131
|
|
|
'crdate' => 'crdate', |
|
132
|
|
|
'cruser_id' => 'cruser_id', |
|
133
|
|
|
'dividers2tabs' => true, |
|
134
|
|
|
|
|
135
|
|
|
'rootLevel' => -1, |
|
136
|
|
|
'security' => [ |
|
137
|
|
|
'ignoreWebMountRestriction' => true, |
|
138
|
|
|
'ignoreRootLevelRestriction' => true, |
|
139
|
|
|
], |
|
140
|
|
|
|
|
141
|
|
|
'languageField' => 'sys_language_uid', |
|
142
|
|
|
'transOrigPointerField' => 'l10n_parent', |
|
143
|
|
|
'transOrigDiffSourceField' => 'l10n_diffsource', |
|
144
|
|
|
'delete' => 'deleted', |
|
145
|
|
|
'enablecolumns' => [ |
|
146
|
|
|
'disabled' => 'hidden', |
|
147
|
|
|
'starttime' => 'starttime', |
|
148
|
|
|
'endtime' => 'endtime', |
|
149
|
|
|
], |
|
150
|
|
|
'searchFields' => 'title,event', |
|
151
|
|
|
'iconfile' => $this->service->getNotificationIconPath(), |
|
152
|
|
|
|
|
153
|
|
|
self::NOTIFICATION_ENTITY => [ |
|
154
|
|
|
'processor' => [ |
|
155
|
|
|
EventConfigurationProcessor::class, |
|
156
|
|
|
], |
|
157
|
|
|
'dataProvider' => [ |
|
158
|
|
|
DefaultEventFromGet::ENABLE_DEFAULT_VALUE => true, |
|
159
|
|
|
] |
|
160
|
|
|
], |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Returns the default TYPO3 columns to include in the final TCA array. |
|
166
|
|
|
*/ |
|
167
|
|
|
private function addDefaultTypo3Columns() |
|
168
|
|
|
{ |
|
169
|
|
|
$defaultColumns = [ |
|
170
|
|
|
'sys_language_uid' => [ |
|
171
|
|
|
'exclude' => 1, |
|
172
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language', |
|
173
|
|
|
'config' => [ |
|
174
|
|
|
'type' => 'select', |
|
175
|
|
|
'renderType' => 'selectSingle', |
|
176
|
|
|
'foreign_table' => 'sys_language', |
|
177
|
|
|
'foreign_table_where' => 'ORDER BY sys_language.title', |
|
178
|
|
|
'default' => 0, |
|
179
|
|
|
'items' => [ |
|
180
|
|
|
['LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1], |
|
181
|
|
|
['LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0], |
|
182
|
|
|
], |
|
183
|
|
|
], |
|
184
|
|
|
], |
|
185
|
|
|
'l10n_parent' => [ |
|
186
|
|
|
'displayCond' => 'FIELD:sys_language_uid:>:0', |
|
187
|
|
|
'exclude' => 1, |
|
188
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent', |
|
189
|
|
|
'l10n_display' => 'defaultAsReadonly', |
|
190
|
|
|
'config' => [ |
|
191
|
|
|
'type' => 'select', |
|
192
|
|
|
'renderType' => 'selectSingle', |
|
193
|
|
|
'foreign_table' => $this->tableName, |
|
194
|
|
|
'foreign_table_where' => "AND {$this->tableName}.pid=###CURRENT_PID### AND {$this->tableName}.sys_language_uid IN (-1,0)", |
|
195
|
|
|
'items' => [ |
|
196
|
|
|
['', 0], |
|
197
|
|
|
], |
|
198
|
|
|
], |
|
199
|
|
|
], |
|
200
|
|
|
'l10n_diffsource' => [ |
|
201
|
|
|
'config' => [ |
|
202
|
|
|
'type' => 'passthrough', |
|
203
|
|
|
], |
|
204
|
|
|
], |
|
205
|
|
|
't3ver_label' => [ |
|
206
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel', |
|
207
|
|
|
'config' => [ |
|
208
|
|
|
'type' => 'input', |
|
209
|
|
|
'size' => 30, |
|
210
|
|
|
'max' => 255, |
|
211
|
|
|
], |
|
212
|
|
|
], |
|
213
|
|
|
'hidden' => [ |
|
214
|
|
|
'exclude' => 1, |
|
215
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden', |
|
216
|
|
|
'config' => [ |
|
217
|
|
|
'type' => 'check', |
|
218
|
|
|
], |
|
219
|
|
|
], |
|
220
|
|
|
'starttime' => [ |
|
221
|
|
|
'exclude' => 1, |
|
222
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime', |
|
223
|
|
|
'config' => [ |
|
224
|
|
|
'type' => 'input', |
|
225
|
|
|
'renderType' => 'inputDateTime', |
|
226
|
|
|
'eval' => 'datetime', |
|
227
|
|
|
'default' => 0, |
|
228
|
|
|
'behaviour' => [ |
|
229
|
|
|
'allowLanguageSynchronization' => true, |
|
230
|
|
|
] |
|
231
|
|
|
] |
|
232
|
|
|
], |
|
233
|
|
|
'endtime' => [ |
|
234
|
|
|
'exclude' => 1, |
|
235
|
|
|
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime', |
|
236
|
|
|
'config' => [ |
|
237
|
|
|
'type' => 'input', |
|
238
|
|
|
'renderType' => 'inputDateTime', |
|
239
|
|
|
'eval' => 'datetime', |
|
240
|
|
|
'default' => 0, |
|
241
|
|
|
'behaviour' => [ |
|
242
|
|
|
'allowLanguageSynchronization' => true, |
|
243
|
|
|
] |
|
244
|
|
|
] |
|
245
|
|
|
], |
|
246
|
|
|
]; |
|
247
|
|
|
|
|
248
|
|
|
ArrayUtility::mergeRecursiveWithOverrule( |
|
249
|
|
|
$this->data['columns'], |
|
250
|
|
|
$defaultColumns |
|
251
|
|
|
); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* This method adds the common columns used by all Entity Notifications. |
|
256
|
|
|
*/ |
|
257
|
|
|
private function addCommonColumns() |
|
258
|
|
|
{ |
|
259
|
|
|
$commonColumns = [ |
|
260
|
|
|
'title' => [ |
|
261
|
|
|
'exclude' => 1, |
|
262
|
|
|
'label' => self::LLL . ":field.title", |
|
263
|
|
|
'config' => [ |
|
264
|
|
|
'type' => 'input', |
|
265
|
|
|
'size' => 30, |
|
266
|
|
|
'eval' => 'trim,required', |
|
267
|
|
|
], |
|
268
|
|
|
], |
|
269
|
|
|
|
|
270
|
|
|
'description' => [ |
|
271
|
|
|
'exclude' => 1, |
|
272
|
|
|
'label' => self::LLL . ":field.description", |
|
273
|
|
|
'config' => [ |
|
274
|
|
|
'type' => 'text', |
|
275
|
|
|
'cols' => 40, |
|
276
|
|
|
'rows' => 5, |
|
277
|
|
|
], |
|
278
|
|
|
], |
|
279
|
|
|
|
|
280
|
|
|
// Event configuration |
|
281
|
|
|
|
|
282
|
|
|
'event' => [ |
|
283
|
|
|
'exclude' => 1, |
|
284
|
|
|
'label' => self::LLL . ":field.event", |
|
285
|
|
|
'l10n_mode' => 'exclude', |
|
286
|
|
|
'onChange' => 'reload', |
|
287
|
|
|
'config' => [ |
|
288
|
|
|
'type' => 'select', |
|
289
|
|
|
'renderType' => 'selectSingle', |
|
290
|
|
|
'size' => 8, |
|
291
|
|
|
'itemsProcFunc' => $this->getNotificationTcaServiceClass() . '->getEventsList', |
|
292
|
|
|
'eval' => 'required', |
|
293
|
|
|
], |
|
294
|
|
|
], |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* This FlexForm field is fully configured in: |
|
298
|
|
|
* @see \CuyZ\Notiz\Core\Notification\TCA\Processor\EventConfigurationProcessor |
|
299
|
|
|
*/ |
|
300
|
|
|
'event_configuration_flex' => [ |
|
301
|
|
|
'label' => self::LLL . ':field.event_configuration', |
|
302
|
|
|
'config' => [ |
|
303
|
|
|
'type' => 'flex', |
|
304
|
|
|
'default' => '', |
|
305
|
|
|
'ds_pointerField' => 'event', |
|
306
|
|
|
'behaviour' => [ |
|
307
|
|
|
'allowLanguageSynchronization' => true, |
|
308
|
|
|
], |
|
309
|
|
|
], |
|
310
|
|
|
], |
|
311
|
|
|
|
|
312
|
|
|
// Channel configuration |
|
313
|
|
|
|
|
314
|
|
|
'channel' => [ |
|
315
|
|
|
'exclude' => 1, |
|
316
|
|
|
'label' => $this->getChannelLabel(), |
|
317
|
|
|
'l10n_mode' => 'exclude', |
|
318
|
|
|
'l10n_display' => 'defaultAsReadonly', |
|
319
|
|
|
'config' => [ |
|
320
|
|
|
'type' => 'select', |
|
321
|
|
|
'renderType' => 'selectSingle', |
|
322
|
|
|
'itemsProcFunc' => $this->getNotificationTcaServiceClass() . '->getChannelsList', |
|
323
|
|
|
'eval' => 'required', |
|
324
|
|
|
], |
|
325
|
|
|
], |
|
326
|
|
|
|
|
327
|
|
|
// Markers configuration |
|
328
|
|
|
|
|
329
|
|
|
'markers' => [ |
|
330
|
|
|
'exclude' => 1, |
|
331
|
|
|
'label' => self::LLL . ":field.markers", |
|
332
|
|
|
'l10n_display' => 'defaultAsReadonly', |
|
333
|
|
|
'config' => [ |
|
334
|
|
|
'type' => 'user', |
|
335
|
|
|
'userFunc' => $this->getNotificationTcaServiceClass() . '->getMarkersLabel', |
|
336
|
|
|
], |
|
337
|
|
|
], |
|
338
|
|
|
]; |
|
339
|
|
|
|
|
340
|
|
|
ArrayUtility::mergeRecursiveWithOverrule( |
|
341
|
|
|
$this->data['columns'], |
|
342
|
|
|
$commonColumns |
|
343
|
|
|
); |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
|