Completed
Push — master ( 5c161a...b70884 )
by Fabien
52:39
created
Classes/Tca/Tca.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -24,132 +24,132 @@
 block discarded – undo
24 24
  */
25 25
 class Tca implements SingletonInterface, TcaServiceInterface
26 26
 {
27
-    /**
28
-     * Fields that are considered as system.
29
-     *
30
-     * @var array
31
-     */
32
-    protected static $systemFields = array(
33
-        'uid',
34
-        'pid',
35
-        'tstamp',
36
-        'crdate',
37
-        'deleted',
38
-        'hidden',
39
-        'sys_language_uid',
40
-        'l18n_parent',
41
-        'l18n_diffsource',
42
-        't3ver_oid',
43
-        't3ver_id',
44
-        't3ver_wsid',
45
-        't3ver_label',
46
-        't3ver_state',
47
-        't3ver_stage',
48
-        't3ver_count',
49
-        't3ver_tstamp',
50
-        't3_origuid',
51
-    );
27
+	/**
28
+	 * Fields that are considered as system.
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected static $systemFields = array(
33
+		'uid',
34
+		'pid',
35
+		'tstamp',
36
+		'crdate',
37
+		'deleted',
38
+		'hidden',
39
+		'sys_language_uid',
40
+		'l18n_parent',
41
+		'l18n_diffsource',
42
+		't3ver_oid',
43
+		't3ver_id',
44
+		't3ver_wsid',
45
+		't3ver_label',
46
+		't3ver_state',
47
+		't3ver_stage',
48
+		't3ver_count',
49
+		't3ver_tstamp',
50
+		't3_origuid',
51
+	);
52 52
 
53
-    /**
54
-     * @var array
55
-     */
56
-    protected static $instances;
53
+	/**
54
+	 * @var array
55
+	 */
56
+	protected static $instances;
57 57
 
58
-    /**
59
-     * Returns a class instance of a corresponding TCA service.
60
-     * If the class instance does not exist, create one.
61
-     *
62
-     * @throws NotExistingClassException
63
-     * @param string $dataType
64
-     * @param string $serviceType
65
-     * @return TcaServiceInterface
66
-     * @throws InvalidKeyInArrayException
67
-     * @throws \InvalidArgumentException
68
-     */
69
-    protected static function getService($dataType, $serviceType)
70
-    {
71
-        if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) {
72
-            /** @var ModuleLoader $moduleLoader */
73
-            $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
74
-            $dataType = $moduleLoader->getDataType();
75
-        }
58
+	/**
59
+	 * Returns a class instance of a corresponding TCA service.
60
+	 * If the class instance does not exist, create one.
61
+	 *
62
+	 * @throws NotExistingClassException
63
+	 * @param string $dataType
64
+	 * @param string $serviceType
65
+	 * @return TcaServiceInterface
66
+	 * @throws InvalidKeyInArrayException
67
+	 * @throws \InvalidArgumentException
68
+	 */
69
+	protected static function getService($dataType, $serviceType)
70
+	{
71
+		if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend() && empty($dataType)) {
72
+			/** @var ModuleLoader $moduleLoader */
73
+			$moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
74
+			$dataType = $moduleLoader->getDataType();
75
+		}
76 76
 
77
-        if (empty(self::$instances[$dataType][$serviceType])) {
78
-            $className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType));
77
+		if (empty(self::$instances[$dataType][$serviceType])) {
78
+			$className = sprintf('Fab\Vidi\Tca\%sService', ucfirst($serviceType));
79 79
 
80
-            // Signal to pre-process the TCA of the given $dataType.
81
-            self::emitPreProcessTcaSignal($dataType, $serviceType);
80
+			// Signal to pre-process the TCA of the given $dataType.
81
+			self::emitPreProcessTcaSignal($dataType, $serviceType);
82 82
 
83
-            $instance = GeneralUtility::makeInstance($className, $dataType, $serviceType);
84
-            self::$instances[$dataType][$serviceType] = $instance;
85
-        }
86
-        return self::$instances[$dataType][$serviceType];
87
-    }
83
+			$instance = GeneralUtility::makeInstance($className, $dataType, $serviceType);
84
+			self::$instances[$dataType][$serviceType] = $instance;
85
+		}
86
+		return self::$instances[$dataType][$serviceType];
87
+	}
88 88
 
89
-    /**
90
-     * Returns a "grid" service instance.
91
-     *
92
-     * @param string|Content $tableNameOrContentObject
93
-     * @return GridService
94
-     * @throws NotExistingClassException
95
-     */
96
-    public static function grid($tableNameOrContentObject = '')
97
-    {
98
-        $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject;
99
-        return self::getService($tableName, self::TYPE_GRID);
100
-    }
89
+	/**
90
+	 * Returns a "grid" service instance.
91
+	 *
92
+	 * @param string|Content $tableNameOrContentObject
93
+	 * @return GridService
94
+	 * @throws NotExistingClassException
95
+	 */
96
+	public static function grid($tableNameOrContentObject = '')
97
+	{
98
+		$tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject;
99
+		return self::getService($tableName, self::TYPE_GRID);
100
+	}
101 101
 
102
-    /**
103
-     * Returns a "table" service instance ("ctrl" part of the TCA).
104
-     *
105
-     * @param string|Content $tableNameOrContentObject
106
-     * @return TableService
107
-     * @throws NotExistingClassException
108
-     */
109
-    public static function table($tableNameOrContentObject = '')
110
-    {
111
-        $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject;
112
-        return self::getService($tableName, self::TYPE_TABLE);
113
-    }
102
+	/**
103
+	 * Returns a "table" service instance ("ctrl" part of the TCA).
104
+	 *
105
+	 * @param string|Content $tableNameOrContentObject
106
+	 * @return TableService
107
+	 * @throws NotExistingClassException
108
+	 */
109
+	public static function table($tableNameOrContentObject = '')
110
+	{
111
+		$tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject;
112
+		return self::getService($tableName, self::TYPE_TABLE);
113
+	}
114 114
 
115
-    /**
116
-     * @return array
117
-     */
118
-    public static function getInstanceStorage()
119
-    {
120
-        return self::$instances;
121
-    }
115
+	/**
116
+	 * @return array
117
+	 */
118
+	public static function getInstanceStorage()
119
+	{
120
+		return self::$instances;
121
+	}
122 122
 
123
-    /**
124
-     * @return array
125
-     */
126
-    public static function getSystemFields()
127
-    {
128
-        return self::$systemFields;
129
-    }
123
+	/**
124
+	 * @return array
125
+	 */
126
+	public static function getSystemFields()
127
+	{
128
+		return self::$systemFields;
129
+	}
130 130
 
131
-    /**
132
-     * Signal that is called after the content repository for a content type has been instantiated.
133
-     *
134
-     * @param string $dataType
135
-     * @param string $serviceType
136
-     * @throws InvalidSlotException
137
-     * @throws InvalidSlotReturnException
138
-     * @throws \InvalidArgumentException
139
-     */
140
-    protected static function emitPreProcessTcaSignal($dataType, $serviceType)
141
-    {
142
-        self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType));
143
-    }
131
+	/**
132
+	 * Signal that is called after the content repository for a content type has been instantiated.
133
+	 *
134
+	 * @param string $dataType
135
+	 * @param string $serviceType
136
+	 * @throws InvalidSlotException
137
+	 * @throws InvalidSlotReturnException
138
+	 * @throws \InvalidArgumentException
139
+	 */
140
+	protected static function emitPreProcessTcaSignal($dataType, $serviceType)
141
+	{
142
+		self::getSignalSlotDispatcher()->dispatch(Tca::class, 'preProcessTca', array($dataType, $serviceType));
143
+	}
144 144
 
145
-    /**
146
-     * Get the SignalSlot dispatcher
147
-     *
148
-     * @return Dispatcher
149
-     * @throws \InvalidArgumentException
150
-     */
151
-    protected static function getSignalSlotDispatcher()
152
-    {
153
-        return GeneralUtility::makeInstance(Dispatcher::class);
154
-    }
145
+	/**
146
+	 * Get the SignalSlot dispatcher
147
+	 *
148
+	 * @return Dispatcher
149
+	 * @throws \InvalidArgumentException
150
+	 */
151
+	protected static function getSignalSlotDispatcher()
152
+	{
153
+		return GeneralUtility::makeInstance(Dispatcher::class);
154
+	}
155 155
 }
Please login to merge, or discard this patch.
Classes/Tca/TableService.php 1 patch
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -19,443 +19,443 @@
 block discarded – undo
19 19
  */
20 20
 class TableService extends AbstractTca
21 21
 {
22
-    /**
23
-     * @var array
24
-     */
25
-    protected $tca;
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $columnTca;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $tableName;
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    protected $instances;
41
-
42
-    /**
43
-     * @throws InvalidKeyInArrayException
44
-     * @param string $tableName
45
-     * @return \Fab\Vidi\Tca\TableService
46
-     */
47
-    public function __construct($tableName)
48
-    {
49
-        $this->tableName = $tableName;
50
-        if (empty($GLOBALS['TCA'][$this->tableName])) {
51
-            throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106);
52
-        }
53
-        $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl'];
54
-        $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns'];
55
-    }
56
-
57
-    /**
58
-     * Tell whether the table has a label field.
59
-     *
60
-     * @throws InvalidKeyInArrayException
61
-     * @return string
62
-     */
63
-    public function hasLabelField()
64
-    {
65
-        return $this->has('label');
66
-    }
67
-
68
-    /**
69
-     * Get the label name of table name.
70
-     *
71
-     * @throws InvalidKeyInArrayException
72
-     * @return string
73
-     */
74
-    public function getLabelField()
75
-    {
76
-        $labelField = $this->get('label');
77
-        if (empty($labelField)) {
78
-            throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726);
79
-        }
80
-        return $labelField;
81
-    }
82
-
83
-    /**
84
-     * Returns the translated label of the table name.
85
-     *
86
-     * @return string
87
-     */
88
-    public function getLabel()
89
-    {
90
-        $label = '';
91
-        try {
92
-            $label = LocalizationUtility::translate($this->getLabelField(), '');
93
-        } catch (\InvalidArgumentException $e) {
94
-        }
95
-        if (empty($label)) {
96
-            $label = $this->getLabelField();
97
-        }
98
-        return $label;
99
-    }
100
-
101
-    /**
102
-     * Returns the title of the table.
103
-     *
104
-     * @return string
105
-     */
106
-    public function getTitle()
107
-    {
108
-        $title = '';
109
-        try {
110
-            $title = LocalizationUtility::translate((string)$this->get('title'), '');
111
-        } catch (\InvalidArgumentException $e) {
112
-        }
113
-        if (empty($title)) {
114
-            $title = $this->get('title');
115
-        }
116
-        return $title;
117
-    }
118
-
119
-    /**
120
-     * Return the "disabled" field.
121
-     *
122
-     * @throws InvalidKeyInArrayException
123
-     * @return string|null
124
-     */
125
-    public function getHiddenField()
126
-    {
127
-        $hiddenField = null;
128
-        $enableColumns = $this->get('enablecolumns');
129
-        if (is_array($enableColumns) && !empty($enableColumns['disabled'])) {
130
-            $hiddenField = $enableColumns['disabled'];
131
-        }
132
-        return $hiddenField;
133
-    }
134
-
135
-    /**
136
-     * Return the "starttime" field.
137
-     *
138
-     * @throws InvalidKeyInArrayException
139
-     * @return string|null
140
-     */
141
-    public function getStartTimeField()
142
-    {
143
-        $startTimeField = null;
144
-        $enableColumns = $this->get('enablecolumns');
145
-        if (is_array($enableColumns) && !empty($enableColumns['starttime'])) {
146
-            $startTimeField = $enableColumns['starttime'];
147
-        }
148
-        return $startTimeField;
149
-    }
150
-
151
-    /**
152
-     * Return the "endtime" field.
153
-     *
154
-     * @throws InvalidKeyInArrayException
155
-     * @return string|null
156
-     */
157
-    public function getEndTimeField()
158
-    {
159
-        $endTimeField = null;
160
-        $enableColumns = $this->get('enablecolumns');
161
-        if (is_array($enableColumns) && !empty($enableColumns['endtime'])) {
162
-            $endTimeField = $enableColumns['endtime'];
163
-        }
164
-        return $endTimeField;
165
-    }
166
-
167
-    /**
168
-     * Tells whether the table is hidden.
169
-     *
170
-     * @return bool
171
-     */
172
-    public function isHidden()
173
-    {
174
-        return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false;
175
-    }
176
-
177
-    /**
178
-     * Tells whether the table is not hidden.
179
-     *
180
-     * @return bool
181
-     */
182
-    public function isNotHidden()
183
-    {
184
-        return !$this->isHidden();
185
-    }
186
-
187
-    /**
188
-     * Get the "deleted" field for the table.
189
-     *
190
-     * @return string|null
191
-     */
192
-    public function getDeletedField()
193
-    {
194
-        return $this->get('delete');
195
-    }
196
-
197
-    /**
198
-     * Get the modification time stamp field.
199
-     *
200
-     * @return string|null
201
-     */
202
-    public function getTimeModificationField()
203
-    {
204
-        return $this->get('tstamp');
205
-    }
206
-
207
-    /**
208
-     * Get the creation time stamp field.
209
-     *
210
-     * @return string|null
211
-     */
212
-    public function getTimeCreationField()
213
-    {
214
-        return $this->get('crdate');
215
-    }
216
-
217
-    /**
218
-     * Get the language field for the table.
219
-     *
220
-     * @return string|null
221
-     */
222
-    public function getLanguageField()
223
-    {
224
-        return $this->get('languageField');
225
-    }
226
-
227
-    /**
228
-     * Get the field which points to the parent.
229
-     *
230
-     * @return string|null
231
-     */
232
-    public function getLanguageParentField()
233
-    {
234
-        return $this->get('transOrigPointerField');
235
-    }
236
-
237
-    /**
238
-     * Returns the default order in the form of a SQL segment.
239
-     *
240
-     * @return string|null
241
-     */
242
-    public function getDefaultOrderSql()
243
-    {
244
-        // "sortby" typically has "sorting" as value.
245
-        $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby');
246
-        return $order;
247
-    }
248
-
249
-    /**
250
-     * Returns the parsed default orderings.
251
-     * Returns array looks like array('title' => 'ASC');
252
-     *
253
-     * @return array
254
-     */
255
-    public function getDefaultOrderings()
256
-    {
257
-        // first clean up the sql segment
258
-        $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql());
259
-        $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true);
260
-
261
-        $orderings = [];
262
-        foreach ($defaultOrderParts as $defaultOrderPart) {
263
-            $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart);
264
-            if (empty($parts[1])) {
265
-                $parts[1] = QueryInterface::ORDER_DESCENDING;
266
-            }
267
-            $orderings[$parts[0]] = $parts[1];
268
-        }
269
-
270
-        return $orderings;
271
-    }
272
-
273
-    /**
274
-     * Returns the searchable fields.
275
-     *
276
-     * @return string|null
277
-     */
278
-    public function getSearchFields()
279
-    {
280
-        return $this->get('searchFields');
281
-    }
282
-
283
-    /**
284
-     * Returns an array containing the field names.
285
-     *
286
-     * @return array
287
-     */
288
-    public function getFields()
289
-    {
290
-        return array_keys($this->columnTca);
291
-    }
292
-
293
-    /**
294
-     * Returns an array containing the fields and their configuration.
295
-     *
296
-     * @return array
297
-     */
298
-    public function getFieldsAndConfiguration()
299
-    {
300
-        return $this->columnTca;
301
-    }
302
-
303
-    /**
304
-     * Tell whether we have a field "sorting".
305
-     *
306
-     * @return bool
307
-     */
308
-    public function hasSortableField()
309
-    {
310
-        return $this->has('sortby');
311
-    }
312
-
313
-    /**
314
-     * Tell whether the field exists or not.
315
-     *
316
-     * @param string $fieldName
317
-     * @return bool
318
-     */
319
-    public function hasField($fieldName)
320
-    {
321
-        if ($this->isComposite($fieldName)) {
322
-            $parts = explode('.', $fieldName);
323
-            list($strippedFieldPath, $possibleTableName) = $parts;
324
-            $hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]);
325
-
326
-            // Continue checking that the $strippedFieldName is of type "group"
327
-            if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) {
328
-                $hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group
329
-            } elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) {
330
-                $hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName.
331
-            }
332
-        } else {
333
-            $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true);
334
-        }
335
-        return $hasField;
336
-    }
337
-
338
-    /**
339
-     * Tell whether the field name contains a path, e.g. metadata.title
340
-     *
341
-     * @param string $fieldName
342
-     * @return boolean
343
-     */
344
-    public function isComposite($fieldName)
345
-    {
346
-        return strpos($fieldName, '.') > 0;
347
-    }
348
-
349
-    /**
350
-     * Tells whether the $key exists.
351
-     *
352
-     * @param string $key
353
-     * @return string
354
-     */
355
-    public function has($key)
356
-    {
357
-        return isset($this->tca[$key]);
358
-    }
359
-
360
-    /**
361
-     * Tells whether the table name has "workspace" support.
362
-     *
363
-     * @return string
364
-     */
365
-    public function hasWorkspaceSupport()
366
-    {
367
-        return isset($this->tca['versioningWS']);
368
-    }
369
-
370
-    /**
371
-     * Tells whether the table name has "language" support.
372
-     *
373
-     * @return string
374
-     */
375
-    public function hasLanguageSupport()
376
-    {
377
-        return isset($this->tca['languageField']);
378
-    }
379
-
380
-    /**
381
-     * Return configuration value given a key.
382
-     *
383
-     * @param string $key
384
-     * @return string|null
385
-     */
386
-    public function get($key)
387
-    {
388
-        return $this->has($key) ? $this->tca[$key] : null;
389
-    }
390
-
391
-    /**
392
-     * @return array
393
-     */
394
-    public function getTca()
395
-    {
396
-        return $this->tca;
397
-    }
398
-
399
-    /**
400
-     * Tell whether the current BE User has access to this field.
401
-     *
402
-     * @return bool
403
-     */
404
-    public function hasAccess()
405
-    {
406
-        $hasAccess = true;
407
-        if ($this->isBackendMode()) {
408
-            $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName);
409
-        }
410
-        return $hasAccess;
411
-    }
412
-
413
-    /**
414
-     * @param string $fieldName
415
-     * @throws \Exception
416
-     * @return FieldService
417
-     */
418
-    public function field($fieldName)
419
-    {
420
-        // In case field contains items.tx_table for field type "group"
421
-        $compositeField = '';
422
-        if (strpos($fieldName, '.') !== false) {
423
-            $compositeField = $fieldName;
424
-            $fieldParts = explode('.', $compositeField, 2);
425
-            $fieldName = $fieldParts[0];
426
-
427
-            // Special when field has been instantiated without the field name and path.
428
-            if (!empty($this->instances[$fieldName])) {
429
-                /** @var FieldService $field */
430
-                $field = $this->instances[$fieldName];
431
-                $field->setCompositeField($compositeField);
432
-            }
433
-        }
434
-
435
-        // True for system fields such as uid, pid that don't necessarily have a TCA.
436
-        if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) {
437
-            $this->columnTca[$fieldName] = [];
438
-        } elseif (empty($this->columnTca[$fieldName])) {
439
-            $message = sprintf(
440
-                'Does the field really exist? No TCA entry found for field "%s" for table "%s"',
441
-                $fieldName,
442
-                $this->tableName
443
-            );
444
-            throw new \Exception($message, 1385554481);
445
-        }
446
-
447
-
448
-        if (empty($this->instances[$fieldName])) {
449
-            $instance = GeneralUtility::makeInstance(
450
-                'Fab\Vidi\Tca\FieldService',
451
-                $fieldName,
452
-                $this->columnTca[$fieldName],
453
-                $this->tableName,
454
-                $compositeField
455
-            );
456
-
457
-            $this->instances[$fieldName] = $instance;
458
-        }
459
-        return $this->instances[$fieldName];
460
-    }
22
+	/**
23
+	 * @var array
24
+	 */
25
+	protected $tca;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $columnTca;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $tableName;
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	protected $instances;
41
+
42
+	/**
43
+	 * @throws InvalidKeyInArrayException
44
+	 * @param string $tableName
45
+	 * @return \Fab\Vidi\Tca\TableService
46
+	 */
47
+	public function __construct($tableName)
48
+	{
49
+		$this->tableName = $tableName;
50
+		if (empty($GLOBALS['TCA'][$this->tableName])) {
51
+			throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106);
52
+		}
53
+		$this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl'];
54
+		$this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns'];
55
+	}
56
+
57
+	/**
58
+	 * Tell whether the table has a label field.
59
+	 *
60
+	 * @throws InvalidKeyInArrayException
61
+	 * @return string
62
+	 */
63
+	public function hasLabelField()
64
+	{
65
+		return $this->has('label');
66
+	}
67
+
68
+	/**
69
+	 * Get the label name of table name.
70
+	 *
71
+	 * @throws InvalidKeyInArrayException
72
+	 * @return string
73
+	 */
74
+	public function getLabelField()
75
+	{
76
+		$labelField = $this->get('label');
77
+		if (empty($labelField)) {
78
+			throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726);
79
+		}
80
+		return $labelField;
81
+	}
82
+
83
+	/**
84
+	 * Returns the translated label of the table name.
85
+	 *
86
+	 * @return string
87
+	 */
88
+	public function getLabel()
89
+	{
90
+		$label = '';
91
+		try {
92
+			$label = LocalizationUtility::translate($this->getLabelField(), '');
93
+		} catch (\InvalidArgumentException $e) {
94
+		}
95
+		if (empty($label)) {
96
+			$label = $this->getLabelField();
97
+		}
98
+		return $label;
99
+	}
100
+
101
+	/**
102
+	 * Returns the title of the table.
103
+	 *
104
+	 * @return string
105
+	 */
106
+	public function getTitle()
107
+	{
108
+		$title = '';
109
+		try {
110
+			$title = LocalizationUtility::translate((string)$this->get('title'), '');
111
+		} catch (\InvalidArgumentException $e) {
112
+		}
113
+		if (empty($title)) {
114
+			$title = $this->get('title');
115
+		}
116
+		return $title;
117
+	}
118
+
119
+	/**
120
+	 * Return the "disabled" field.
121
+	 *
122
+	 * @throws InvalidKeyInArrayException
123
+	 * @return string|null
124
+	 */
125
+	public function getHiddenField()
126
+	{
127
+		$hiddenField = null;
128
+		$enableColumns = $this->get('enablecolumns');
129
+		if (is_array($enableColumns) && !empty($enableColumns['disabled'])) {
130
+			$hiddenField = $enableColumns['disabled'];
131
+		}
132
+		return $hiddenField;
133
+	}
134
+
135
+	/**
136
+	 * Return the "starttime" field.
137
+	 *
138
+	 * @throws InvalidKeyInArrayException
139
+	 * @return string|null
140
+	 */
141
+	public function getStartTimeField()
142
+	{
143
+		$startTimeField = null;
144
+		$enableColumns = $this->get('enablecolumns');
145
+		if (is_array($enableColumns) && !empty($enableColumns['starttime'])) {
146
+			$startTimeField = $enableColumns['starttime'];
147
+		}
148
+		return $startTimeField;
149
+	}
150
+
151
+	/**
152
+	 * Return the "endtime" field.
153
+	 *
154
+	 * @throws InvalidKeyInArrayException
155
+	 * @return string|null
156
+	 */
157
+	public function getEndTimeField()
158
+	{
159
+		$endTimeField = null;
160
+		$enableColumns = $this->get('enablecolumns');
161
+		if (is_array($enableColumns) && !empty($enableColumns['endtime'])) {
162
+			$endTimeField = $enableColumns['endtime'];
163
+		}
164
+		return $endTimeField;
165
+	}
166
+
167
+	/**
168
+	 * Tells whether the table is hidden.
169
+	 *
170
+	 * @return bool
171
+	 */
172
+	public function isHidden()
173
+	{
174
+		return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false;
175
+	}
176
+
177
+	/**
178
+	 * Tells whether the table is not hidden.
179
+	 *
180
+	 * @return bool
181
+	 */
182
+	public function isNotHidden()
183
+	{
184
+		return !$this->isHidden();
185
+	}
186
+
187
+	/**
188
+	 * Get the "deleted" field for the table.
189
+	 *
190
+	 * @return string|null
191
+	 */
192
+	public function getDeletedField()
193
+	{
194
+		return $this->get('delete');
195
+	}
196
+
197
+	/**
198
+	 * Get the modification time stamp field.
199
+	 *
200
+	 * @return string|null
201
+	 */
202
+	public function getTimeModificationField()
203
+	{
204
+		return $this->get('tstamp');
205
+	}
206
+
207
+	/**
208
+	 * Get the creation time stamp field.
209
+	 *
210
+	 * @return string|null
211
+	 */
212
+	public function getTimeCreationField()
213
+	{
214
+		return $this->get('crdate');
215
+	}
216
+
217
+	/**
218
+	 * Get the language field for the table.
219
+	 *
220
+	 * @return string|null
221
+	 */
222
+	public function getLanguageField()
223
+	{
224
+		return $this->get('languageField');
225
+	}
226
+
227
+	/**
228
+	 * Get the field which points to the parent.
229
+	 *
230
+	 * @return string|null
231
+	 */
232
+	public function getLanguageParentField()
233
+	{
234
+		return $this->get('transOrigPointerField');
235
+	}
236
+
237
+	/**
238
+	 * Returns the default order in the form of a SQL segment.
239
+	 *
240
+	 * @return string|null
241
+	 */
242
+	public function getDefaultOrderSql()
243
+	{
244
+		// "sortby" typically has "sorting" as value.
245
+		$order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby');
246
+		return $order;
247
+	}
248
+
249
+	/**
250
+	 * Returns the parsed default orderings.
251
+	 * Returns array looks like array('title' => 'ASC');
252
+	 *
253
+	 * @return array
254
+	 */
255
+	public function getDefaultOrderings()
256
+	{
257
+		// first clean up the sql segment
258
+		$defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql());
259
+		$defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true);
260
+
261
+		$orderings = [];
262
+		foreach ($defaultOrderParts as $defaultOrderPart) {
263
+			$parts = GeneralUtility::trimExplode(' ', $defaultOrderPart);
264
+			if (empty($parts[1])) {
265
+				$parts[1] = QueryInterface::ORDER_DESCENDING;
266
+			}
267
+			$orderings[$parts[0]] = $parts[1];
268
+		}
269
+
270
+		return $orderings;
271
+	}
272
+
273
+	/**
274
+	 * Returns the searchable fields.
275
+	 *
276
+	 * @return string|null
277
+	 */
278
+	public function getSearchFields()
279
+	{
280
+		return $this->get('searchFields');
281
+	}
282
+
283
+	/**
284
+	 * Returns an array containing the field names.
285
+	 *
286
+	 * @return array
287
+	 */
288
+	public function getFields()
289
+	{
290
+		return array_keys($this->columnTca);
291
+	}
292
+
293
+	/**
294
+	 * Returns an array containing the fields and their configuration.
295
+	 *
296
+	 * @return array
297
+	 */
298
+	public function getFieldsAndConfiguration()
299
+	{
300
+		return $this->columnTca;
301
+	}
302
+
303
+	/**
304
+	 * Tell whether we have a field "sorting".
305
+	 *
306
+	 * @return bool
307
+	 */
308
+	public function hasSortableField()
309
+	{
310
+		return $this->has('sortby');
311
+	}
312
+
313
+	/**
314
+	 * Tell whether the field exists or not.
315
+	 *
316
+	 * @param string $fieldName
317
+	 * @return bool
318
+	 */
319
+	public function hasField($fieldName)
320
+	{
321
+		if ($this->isComposite($fieldName)) {
322
+			$parts = explode('.', $fieldName);
323
+			list($strippedFieldPath, $possibleTableName) = $parts;
324
+			$hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]);
325
+
326
+			// Continue checking that the $strippedFieldName is of type "group"
327
+			if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) {
328
+				$hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group
329
+			} elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) {
330
+				$hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName.
331
+			}
332
+		} else {
333
+			$hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true);
334
+		}
335
+		return $hasField;
336
+	}
337
+
338
+	/**
339
+	 * Tell whether the field name contains a path, e.g. metadata.title
340
+	 *
341
+	 * @param string $fieldName
342
+	 * @return boolean
343
+	 */
344
+	public function isComposite($fieldName)
345
+	{
346
+		return strpos($fieldName, '.') > 0;
347
+	}
348
+
349
+	/**
350
+	 * Tells whether the $key exists.
351
+	 *
352
+	 * @param string $key
353
+	 * @return string
354
+	 */
355
+	public function has($key)
356
+	{
357
+		return isset($this->tca[$key]);
358
+	}
359
+
360
+	/**
361
+	 * Tells whether the table name has "workspace" support.
362
+	 *
363
+	 * @return string
364
+	 */
365
+	public function hasWorkspaceSupport()
366
+	{
367
+		return isset($this->tca['versioningWS']);
368
+	}
369
+
370
+	/**
371
+	 * Tells whether the table name has "language" support.
372
+	 *
373
+	 * @return string
374
+	 */
375
+	public function hasLanguageSupport()
376
+	{
377
+		return isset($this->tca['languageField']);
378
+	}
379
+
380
+	/**
381
+	 * Return configuration value given a key.
382
+	 *
383
+	 * @param string $key
384
+	 * @return string|null
385
+	 */
386
+	public function get($key)
387
+	{
388
+		return $this->has($key) ? $this->tca[$key] : null;
389
+	}
390
+
391
+	/**
392
+	 * @return array
393
+	 */
394
+	public function getTca()
395
+	{
396
+		return $this->tca;
397
+	}
398
+
399
+	/**
400
+	 * Tell whether the current BE User has access to this field.
401
+	 *
402
+	 * @return bool
403
+	 */
404
+	public function hasAccess()
405
+	{
406
+		$hasAccess = true;
407
+		if ($this->isBackendMode()) {
408
+			$hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName);
409
+		}
410
+		return $hasAccess;
411
+	}
412
+
413
+	/**
414
+	 * @param string $fieldName
415
+	 * @throws \Exception
416
+	 * @return FieldService
417
+	 */
418
+	public function field($fieldName)
419
+	{
420
+		// In case field contains items.tx_table for field type "group"
421
+		$compositeField = '';
422
+		if (strpos($fieldName, '.') !== false) {
423
+			$compositeField = $fieldName;
424
+			$fieldParts = explode('.', $compositeField, 2);
425
+			$fieldName = $fieldParts[0];
426
+
427
+			// Special when field has been instantiated without the field name and path.
428
+			if (!empty($this->instances[$fieldName])) {
429
+				/** @var FieldService $field */
430
+				$field = $this->instances[$fieldName];
431
+				$field->setCompositeField($compositeField);
432
+			}
433
+		}
434
+
435
+		// True for system fields such as uid, pid that don't necessarily have a TCA.
436
+		if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) {
437
+			$this->columnTca[$fieldName] = [];
438
+		} elseif (empty($this->columnTca[$fieldName])) {
439
+			$message = sprintf(
440
+				'Does the field really exist? No TCA entry found for field "%s" for table "%s"',
441
+				$fieldName,
442
+				$this->tableName
443
+			);
444
+			throw new \Exception($message, 1385554481);
445
+		}
446
+
447
+
448
+		if (empty($this->instances[$fieldName])) {
449
+			$instance = GeneralUtility::makeInstance(
450
+				'Fab\Vidi\Tca\FieldService',
451
+				$fieldName,
452
+				$this->columnTca[$fieldName],
453
+				$this->tableName,
454
+				$compositeField
455
+			);
456
+
457
+			$this->instances[$fieldName] = $instance;
458
+		}
459
+		return $this->instances[$fieldName];
460
+	}
461 461
 }
Please login to merge, or discard this patch.
Classes/Tca/TcaServiceInterface.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@
 block discarded – undo
14 14
  */
15 15
 interface TcaServiceInterface
16 16
 {
17
-    public const TYPE_TABLE = 'table';
17
+	public const TYPE_TABLE = 'table';
18 18
 
19
-    public const TYPE_FIELD = 'field';
19
+	public const TYPE_FIELD = 'field';
20 20
 
21
-    public const TYPE_GRID = 'grid';
21
+	public const TYPE_GRID = 'grid';
22 22
 
23
-    public const TYPE_FORM = 'form';
23
+	public const TYPE_FORM = 'form';
24 24
 
25
-    public const TYPE_FACET = 'facet';
25
+	public const TYPE_FACET = 'facet';
26 26
 }
Please login to merge, or discard this patch.
Classes/Tca/AbstractTca.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@
 block discarded – undo
16 16
  */
17 17
 abstract class AbstractTca implements TcaServiceInterface
18 18
 {
19
-    /**
20
-     * Returns an instance of the current Backend User.
21
-     *
22
-     * @return BackendUserAuthentication
23
-     */
24
-    protected function getBackendUser()
25
-    {
26
-        return $GLOBALS['BE_USER'];
27
-    }
19
+	/**
20
+	 * Returns an instance of the current Backend User.
21
+	 *
22
+	 * @return BackendUserAuthentication
23
+	 */
24
+	protected function getBackendUser()
25
+	{
26
+		return $GLOBALS['BE_USER'];
27
+	}
28 28
 
29
-    /**
30
-     * Returns whether the current mode is Backend.
31
-     *
32
-     * @return bool
33
-     */
34
-    protected function isBackendMode()
35
-    {
36
-        return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();
37
-    }
29
+	/**
30
+	 * Returns whether the current mode is Backend.
31
+	 *
32
+	 * @return bool
33
+	 */
34
+	protected function isBackendMode()
35
+	{
36
+		return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();
37
+	}
38 38
 
39
-    /**
40
-     * Returns whether the current mode is Frontend.
41
-     *
42
-     * @return bool
43
-     */
44
-    protected function isFrontendMode()
45
-    {
46
-        return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
47
-    }
39
+	/**
40
+	 * Returns whether the current mode is Frontend.
41
+	 *
42
+	 * @return bool
43
+	 */
44
+	protected function isFrontendMode()
45
+	{
46
+		return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Classes/Tca/FieldType.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
  */
17 17
 class FieldType extends Enumeration
18 18
 {
19
-    public const TEXT = 'text';
19
+	public const TEXT = 'text';
20 20
 
21
-    public const NUMBER = 'number';
21
+	public const NUMBER = 'number';
22 22
 
23
-    public const EMAIL = 'email';
23
+	public const EMAIL = 'email';
24 24
 
25
-    public const DATE = 'date';
25
+	public const DATE = 'date';
26 26
 
27
-    public const DATETIME = 'datetime';
27
+	public const DATETIME = 'datetime';
28 28
 
29
-    public const TEXTAREA = 'textarea';
29
+	public const TEXTAREA = 'textarea';
30 30
 
31
-    public const SELECT = 'select';
31
+	public const SELECT = 'select';
32 32
 
33
-    public const RADIO = 'radio';
33
+	public const RADIO = 'radio';
34 34
 
35
-    public const CHECKBOX = 'check';
35
+	public const CHECKBOX = 'check';
36 36
 
37
-    public const FILE = 'file';
37
+	public const FILE = 'file';
38 38
 
39
-    public const MULTISELECT = 'multiselect';
39
+	public const MULTISELECT = 'multiselect';
40 40
 
41
-    public const TREE = 'tree';
41
+	public const TREE = 'tree';
42 42
 }
Please login to merge, or discard this patch.
Classes/Tca/FieldService.php 1 patch
Indentation   +761 added lines, -761 removed lines patch added patch discarded remove patch
@@ -18,765 +18,765 @@
 block discarded – undo
18 18
  */
19 19
 class FieldService extends AbstractTca
20 20
 {
21
-    /**
22
-     * @var string
23
-     */
24
-    protected $fieldName;
25
-
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $compositeField;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $tableName;
35
-
36
-    /**
37
-     * @var array
38
-     */
39
-    protected $tca;
40
-
41
-    /**
42
-     * @param string $fieldName
43
-     * @param array $tca
44
-     * @param string $tableName
45
-     * @param string $compositeField
46
-     * @return \Fab\Vidi\Tca\FieldService
47
-     */
48
-    public function __construct($fieldName, array $tca, $tableName, $compositeField = '')
49
-    {
50
-        $this->fieldName = $fieldName;
51
-        $this->tca = $tca;
52
-        $this->tableName = $tableName;
53
-        $this->compositeField = $compositeField;
54
-    }
55
-
56
-    /**
57
-     * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc...
58
-     *
59
-     * @return bool
60
-     */
61
-    public function isSystem()
62
-    {
63
-        return in_array($this->fieldName, Tca::getSystemFields());
64
-    }
65
-
66
-    /**
67
-     * Tells the opposition of isSystem()
68
-     *
69
-     * @return bool
70
-     */
71
-    public function isNotSystem()
72
-    {
73
-        return !$this->isSystem();
74
-    }
75
-
76
-    /**
77
-     * Returns the configuration for a $field
78
-     *
79
-     * @throws \Exception
80
-     * @return array
81
-     */
82
-    public function getConfiguration()
83
-    {
84
-        return empty($this->tca['config']) ? [] : $this->tca['config'];
85
-    }
86
-
87
-    /**
88
-     * Returns a key of the configuration.
89
-     * If the key can not to be found, returns null.
90
-     *
91
-     * @param string $key
92
-     * @return mixed
93
-     */
94
-    public function get($key)
95
-    {
96
-        $configuration = $this->getConfiguration();
97
-        return empty($configuration[$key]) ? null : $configuration[$key];
98
-    }
99
-
100
-    /**
101
-     * Returns the foreign field of a given field (opposite relational field).
102
-     * If no relation exists, returns null.
103
-     *
104
-     * @return string|null
105
-     */
106
-    public function getForeignField()
107
-    {
108
-        $result = null;
109
-        $configuration = $this->getConfiguration();
110
-
111
-        if (!empty($configuration['foreign_field'])) {
112
-            $result = $configuration['foreign_field'];
113
-        } elseif ($this->hasRelationManyToMany()) {
114
-            $foreignTable = $this->getForeignTable();
115
-            $manyToManyTable = $this->getManyToManyTable();
116
-
117
-            // Load TCA service of foreign field.
118
-            $tcaForeignTableService = Tca::table($foreignTable);
119
-
120
-            // Look into the MM relations checking for the opposite field
121
-            foreach ($tcaForeignTableService->getFields() as $fieldName) {
122
-                if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) {
123
-                    $result = $fieldName;
124
-                    break;
125
-                }
126
-            }
127
-        }
128
-        return $result;
129
-    }
130
-
131
-    /**
132
-     * Returns the foreign table of a given field (opposite relational table).
133
-     * If no relation exists, returns null.
134
-     *
135
-     * @return string|null
136
-     */
137
-    public function getForeignTable()
138
-    {
139
-        $result = null;
140
-        $configuration = $this->getConfiguration();
141
-
142
-        if (!empty($configuration['foreign_table'])) {
143
-            $result = $configuration['foreign_table'];
144
-        } elseif ($this->isGroup()) {
145
-            $fieldParts = explode('.', $this->compositeField, 2);
146
-            $result = $fieldParts[1];
147
-        }
148
-        return $result;
149
-    }
150
-
151
-    /**
152
-     * Returns the foreign clause.
153
-     * If no foreign order exists, returns empty string.
154
-     *
155
-     * @return string
156
-     */
157
-    public function getForeignClause()
158
-    {
159
-        $result = '';
160
-        $configuration = $this->getConfiguration();
161
-
162
-        if (!empty($configuration['foreign_table_where'])) {
163
-            $parts = explode('ORDER BY', $configuration['foreign_table_where']);
164
-            if (!empty($parts[0])) {
165
-                $result = $parts[0];
166
-            }
167
-        }
168
-
169
-        // Substitute some variables
170
-        return $this->substituteKnownMarkers($result);
171
-    }
172
-
173
-    /**
174
-     * Substitute some known markers from the where clause in the Frontend Context.
175
-     *
176
-     * @param string $clause
177
-     * @return string
178
-     */
179
-    protected function substituteKnownMarkers($clause)
180
-    {
181
-        if ($clause && $this->isFrontendMode()) {
182
-            $searches = array(
183
-                '###CURRENT_PID###',
184
-                '###REC_FIELD_sys_language_uid###'
185
-            );
186
-
187
-            $replaces = array(
188
-                $this->getFrontendObject()->id,
189
-                GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id'),
190
-            );
191
-
192
-            $clause = str_replace($searches, $replaces, $clause);
193
-        }
194
-        return $clause;
195
-    }
196
-
197
-    /**
198
-     * Returns the foreign order of the current field.
199
-     * If no foreign order exists, returns empty string.
200
-     *
201
-     * @return string
202
-     */
203
-    public function getForeignOrder()
204
-    {
205
-        $result = '';
206
-        $configuration = $this->getConfiguration();
207
-
208
-        if (!empty($configuration['foreign_table_where'])) {
209
-            $parts = explode('ORDER BY', $configuration['foreign_table_where']);
210
-            if (!empty($parts[1])) {
211
-                $result = $parts[1];
212
-            }
213
-        }
214
-        return $result;
215
-    }
216
-
217
-    /**
218
-     * Returns the MM table of a field.
219
-     * If no relation exists, returns null.
220
-     *
221
-     * @return string|null
222
-     */
223
-    public function getManyToManyTable()
224
-    {
225
-        $configuration = $this->getConfiguration();
226
-        return empty($configuration['MM']) ? null : $configuration['MM'];
227
-    }
228
-
229
-    /**
230
-     * Returns a possible additional table name used in MM relations.
231
-     * If no table name exists, returns null.
232
-     *
233
-     * @return string|null
234
-     */
235
-    public function getAdditionalTableNameCondition()
236
-    {
237
-        $result = null;
238
-        $configuration = $this->getConfiguration();
239
-
240
-        if (!empty($configuration['MM_match_fields']['tablenames'])) {
241
-            $result = $configuration['MM_match_fields']['tablenames'];
242
-        } elseif ($this->isGroup()) {
243
-            // @todo check if $this->fieldName could be simply used as $result
244
-            $fieldParts = explode('.', $this->compositeField, 2);
245
-            $result = $fieldParts[1];
246
-        }
247
-
248
-        return $result;
249
-    }
250
-
251
-    /**
252
-     * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc...
253
-     *
254
-     * @return array
255
-     */
256
-    public function getAdditionalMMCondition()
257
-    {
258
-        $additionalMMConditions = [];
259
-        $configuration = $this->getConfiguration();
260
-
261
-        if (!empty($configuration['MM_match_fields'])) {
262
-            $additionalMMConditions = $configuration['MM_match_fields'];
263
-        }
264
-
265
-        // Add in any case a table name for "group"
266
-        if ($this->isGroup()) {
267
-            // @todo check if $this->fieldName could be simply used as $result
268
-            $fieldParts = explode('.', $this->compositeField, 2);
269
-            $additionalMMConditions = array(
270
-                'tablenames' => $fieldParts[1],
271
-            );
272
-        }
273
-        return $additionalMMConditions;
274
-    }
275
-
276
-    /**
277
-     * Returns whether the field name is the opposite in MM relation.
278
-     *
279
-     * @return bool
280
-     */
281
-    public function isOppositeRelation()
282
-    {
283
-        $configuration = $this->getConfiguration();
284
-        return isset($configuration['MM_opposite_field']);
285
-    }
286
-
287
-    /**
288
-     * Returns the configuration for a $field.
289
-     *
290
-     * @throws \Exception
291
-     * @return string
292
-     */
293
-    public function getType()
294
-    {
295
-        if ($this->isSystem()) {
296
-            $fieldType = FieldType::NUMBER;
297
-        } else {
298
-            $configuration = $this->getConfiguration();
299
-
300
-            if (empty($configuration['type'])) {
301
-                throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627);
302
-            }
303
-
304
-            $fieldType = $configuration['type'];
305
-
306
-            if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) {
307
-                $fieldType = FieldType::MULTISELECT;
308
-            } elseif (!empty($configuration['foreign_table'])
309
-                && ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file')
310
-            ) {
311
-                $fieldType = FieldType::FILE;
312
-            } elseif (!empty($configuration['eval'])) {
313
-                $parts = GeneralUtility::trimExplode(',', $configuration['eval']);
314
-                if (in_array('datetime', $parts)) {
315
-                    $fieldType = FieldType::DATETIME;
316
-                } elseif (in_array('date', $parts)) {
317
-                    $fieldType = FieldType::DATE;
318
-                } elseif (in_array('email', $parts)) {
319
-                    $fieldType = FieldType::EMAIL;
320
-                } elseif (in_array('int', $parts) || in_array('double2', $parts)) {
321
-                    $fieldType = FieldType::NUMBER;
322
-                }
323
-            }
324
-
325
-            // Do some legacy conversion
326
-            if ($fieldType === 'input') {
327
-                $fieldType = FieldType::TEXT;
328
-            } elseif ($fieldType === 'text') {
329
-                $fieldType = FieldType::TEXTAREA;
330
-            }
331
-        }
332
-        return $fieldType;
333
-    }
334
-
335
-    /**
336
-     * Return the default value.
337
-     *
338
-     * @return bool
339
-     */
340
-    public function getDefaultValue()
341
-    {
342
-        $configuration = $this->getConfiguration();
343
-        return isset($configuration['default']) ? $configuration['default'] : null;
344
-    }
345
-
346
-    /**
347
-     * Get the translation of a label given a column.
348
-     *
349
-     * @return string
350
-     */
351
-    public function getLabel()
352
-    {
353
-        $label = '';
354
-        if ($this->hasLabel()) {
355
-            try {
356
-                $label = LocalizationUtility::translate($this->tca['label'], '');
357
-            } catch (\InvalidArgumentException $e) {
358
-            }
359
-            if (empty($label)) {
360
-                $label = $this->tca['label'];
361
-            }
362
-        }
363
-        return $label;
364
-    }
365
-
366
-    /**
367
-     * Get the translation of a label given a column.
368
-     *
369
-     * @param string $itemValue the item value to search for.
370
-     * @return string
371
-     */
372
-    public function getLabelForItem($itemValue)
373
-    {
374
-        // Early return whether there is nothing to be translated as label.
375
-        if (is_null($itemValue)) {
376
-            return '';
377
-        } elseif (is_string($itemValue) && $itemValue === '') {
378
-            return $itemValue;
379
-        }
380
-
381
-        $configuration = $this->getConfiguration();
382
-        if (!empty($configuration['items']) && is_array($configuration['items'])) {
383
-            foreach ($configuration['items'] as $item) {
384
-                if ($item[1] == $itemValue) {
385
-                    try {
386
-                        $label = LocalizationUtility::translate($item[0], '');
387
-                    } catch (\InvalidArgumentException $e) {
388
-                    }
389
-                    if (empty($label)) {
390
-                        $label = $item[0];
391
-                    }
392
-                    break;
393
-                }
394
-            }
395
-        }
396
-
397
-        // Try fetching a label from a possible itemsProcFunc
398
-        if (!isset($label) && is_scalar($itemValue)) {
399
-            $items = $this->fetchItemsFromUserFunction();
400
-            if (!empty($items[$itemValue])) {
401
-                $label = $items[$itemValue];
402
-            }
403
-        }
404
-
405
-        // Returns a label if it has been found, otherwise returns the item value as fallback.
406
-        return isset($label) ? $label : $itemValue;
407
-    }
408
-
409
-    /**
410
-     * Retrieve items from User Function.
411
-     *
412
-     * @return array
413
-     */
414
-    protected function fetchItemsFromUserFunction()
415
-    {
416
-        $values = [];
417
-
418
-        $configuration = $this->getConfiguration();
419
-        if (!empty($configuration['itemsProcFunc'])) {
420
-            $parts = explode('php:', $configuration['itemsProcFunc']);
421
-            if (!empty($parts[1])) {
422
-                list($class, $method) = explode('->', $parts[1]);
423
-
424
-                $parameters['items'] = [];
425
-                $object = GeneralUtility::makeInstance($class);
426
-                $object->$method($parameters);
427
-
428
-                foreach ($parameters['items'] as $items) {
429
-                    $values[$items[1]] = $items[0];
430
-                }
431
-            }
432
-        }
433
-        return $values;
434
-    }
435
-
436
-    /**
437
-     * Get a possible icon given a field name an an item.
438
-     *
439
-     * @param string $itemValue the item value to search for.
440
-     * @return string
441
-     */
442
-    public function getIconForItem($itemValue)
443
-    {
444
-        $result = '';
445
-        $configuration = $this->getConfiguration();
446
-        if (!empty($configuration['items']) && is_array($configuration['items'])) {
447
-            foreach ($configuration['items'] as $item) {
448
-                if ($item[1] == $itemValue) {
449
-                    $result = empty($item[2]) ? '' : $item[2];
450
-                    break;
451
-                }
452
-            }
453
-        }
454
-        return $result;
455
-    }
456
-
457
-    /**
458
-     * Returns whether the field has a label.
459
-     *
460
-     * @return bool
461
-     */
462
-    public function hasLabel()
463
-    {
464
-        return empty($this->tca['label']) ? false : true;
465
-    }
466
-
467
-    /**
468
-     * Tell whether the current BE User has access to this field.
469
-     *
470
-     * @return bool
471
-     */
472
-    public function hasAccess()
473
-    {
474
-        $hasAccess = true;
475
-        if ($this->isBackendMode()
476
-            && Tca::table($this->tableName)->hasAccess()
477
-            && isset($this->tca['exclude'])
478
-            && $this->tca['exclude']
479
-        ) {
480
-            $hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName);
481
-        }
482
-        return $hasAccess;
483
-    }
484
-
485
-    /**
486
-     * Returns whether the field is numerical.
487
-     *
488
-     * @return bool
489
-     */
490
-    public function isNumerical()
491
-    {
492
-        $result = $this->isSystem();
493
-        if ($result === false) {
494
-            $configuration = $this->getConfiguration();
495
-            $parts = [];
496
-            if (!empty($configuration['eval'])) {
497
-                $parts = GeneralUtility::trimExplode(',', $configuration['eval']);
498
-            }
499
-            $result = in_array('int', $parts) || in_array('float', $parts);
500
-        }
501
-        return $result;
502
-    }
503
-
504
-    /**
505
-     * Returns whether the field is of type text area.
506
-     *
507
-     * @return bool
508
-     */
509
-    public function isTextArea()
510
-    {
511
-        return $this->getType() === FieldType::TEXTAREA;
512
-    }
513
-    /**
514
-     * Returns whether the field is of type text area.
515
-     *
516
-     * @return bool
517
-     */
518
-    public function isText()
519
-    {
520
-        return $this->getType() === FieldType::TEXT;
521
-    }
522
-
523
-    /**
524
-     * Returns whether the field is displayed as a tree.
525
-     *
526
-     * @return bool
527
-     */
528
-    public function isRenderModeTree()
529
-    {
530
-        $configuration = $this->getConfiguration();
531
-        return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE;
532
-    }
533
-
534
-    /**
535
-     * Returns whether the field is of type select.
536
-     *
537
-     * @return bool
538
-     */
539
-    public function isSelect()
540
-    {
541
-        return $this->getType() === FieldType::SELECT;
542
-    }
543
-
544
-    /**
545
-     * Returns whether the field is of type select.
546
-     *
547
-     * @return bool
548
-     */
549
-    public function isMultipleSelect()
550
-    {
551
-        return $this->getType() === FieldType::MULTISELECT;
552
-    }
553
-
554
-    /**
555
-     * Returns whether the field is of type select.
556
-     *
557
-     * @return bool
558
-     */
559
-    public function isCheckBox()
560
-    {
561
-        return $this->getType() === FieldType::CHECKBOX;
562
-    }
563
-
564
-    /**
565
-     * Returns whether the field is of type db.
566
-     *
567
-     * @return bool
568
-     */
569
-    public function isGroup()
570
-    {
571
-        return $this->getType() === 'group';
572
-    }
573
-
574
-    /**
575
-     * Returns whether the field is language aware.
576
-     *
577
-     * @return bool
578
-     */
579
-    public function isLocalized()
580
-    {
581
-        $isLocalized = false;
582
-        if (isset($this->tca['l10n_mode'])) {
583
-            if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') {
584
-                $isLocalized = true;
585
-            }
586
-        }
587
-        return $isLocalized;
588
-    }
589
-
590
-    /**
591
-     * Returns whether the field is required.
592
-     *
593
-     * @return bool
594
-     */
595
-    public function isRequired()
596
-    {
597
-        $configuration = $this->getConfiguration();
598
-
599
-        $isRequired = false;
600
-        if (isset($configuration['minitems'])) {
601
-            // is required of a select?
602
-            $isRequired = $configuration['minitems'] == 1 ? true : false;
603
-        } elseif (isset($configuration['eval'])) {
604
-            $parts = GeneralUtility::trimExplode(',', $configuration['eval'], true);
605
-            $isRequired = in_array('required', $parts);
606
-        }
607
-        return $isRequired;
608
-    }
609
-
610
-    /**
611
-     * Returns an array containing the configuration of a column.
612
-     *
613
-     * @return array
614
-     */
615
-    public function getField()
616
-    {
617
-        return $this->tca;
618
-    }
619
-
620
-    /**
621
-     * Returns the relation type
622
-     *
623
-     * @return string
624
-     */
625
-    public function relationDataType()
626
-    {
627
-        $configuration = $this->getConfiguration();
628
-        return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table'];
629
-    }
630
-
631
-    /**
632
-     * Returns whether the field has relation (one to many, many to many)
633
-     *
634
-     * @return bool
635
-     */
636
-    public function hasRelation()
637
-    {
638
-        return null !== $this->getForeignTable();
639
-    }
640
-
641
-    /**
642
-     * Returns whether the field has no relation (one to many, many to many)
643
-     *
644
-     * @return bool
645
-     */
646
-    public function hasNoRelation()
647
-    {
648
-        return !$this->hasRelation();
649
-    }
650
-
651
-    /**
652
-     * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many".
653
-     *
654
-     * @return bool
655
-     */
656
-    public function hasMany()
657
-    {
658
-        $configuration = $this->getConfiguration();
659
-        return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field']));
660
-    }
661
-
662
-    /**
663
-     * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one".
664
-     *
665
-     * @return bool
666
-     */
667
-    public function hasOne()
668
-    {
669
-        $configuration = $this->getConfiguration();
670
-        return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems']));
671
-    }
672
-
673
-    /**
674
-     * Returns whether the field has many-to-one relation.
675
-     *
676
-     * @return bool
677
-     */
678
-    public function hasRelationManyToOne()
679
-    {
680
-        $result = false;
681
-
682
-        $foreignField = $this->getForeignField();
683
-        if (!empty($foreignField)) {
684
-            // Load TCA service of the foreign field.
685
-            $foreignTable = $this->getForeignTable();
686
-            $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany();
687
-        }
688
-        return $result;
689
-    }
690
-
691
-    /**
692
-     * Returns whether the field has one-to-many relation.
693
-     *
694
-     * @return bool
695
-     */
696
-    public function hasRelationOneToMany()
697
-    {
698
-        $result = false;
699
-
700
-        $foreignField = $this->getForeignField();
701
-        if (!empty($foreignField)) {
702
-            // Load TCA service of the foreign field.
703
-            $foreignTable = $this->getForeignTable();
704
-            $result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne();
705
-        }
706
-        return $result;
707
-    }
708
-
709
-    /**
710
-     * Returns whether the field has one-to-one relation.
711
-     *
712
-     * @return bool
713
-     */
714
-    public function hasRelationOneToOne()
715
-    {
716
-        $result = false;
717
-
718
-        $foreignField = $this->getForeignField();
719
-        if (!empty($foreignField)) {
720
-            // Load TCA service of foreign field.
721
-            $foreignTable = $this->getForeignTable();
722
-            $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne();
723
-        }
724
-        return $result;
725
-    }
726
-
727
-    /**
728
-     * Returns whether the field has many to many relation.
729
-     *
730
-     * @return bool
731
-     */
732
-    public function hasRelationManyToMany()
733
-    {
734
-        $configuration = $this->getConfiguration();
735
-        return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field']));
736
-    }
737
-
738
-    /**
739
-     * Returns whether the field has many to many relation using comma separated values (legacy).
740
-     *
741
-     * @return bool
742
-     */
743
-    public function hasRelationWithCommaSeparatedValues()
744
-    {
745
-        $configuration = $this->getConfiguration();
746
-        return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1;
747
-    }
748
-
749
-    /**
750
-     * @return array
751
-     */
752
-    public function getTca()
753
-    {
754
-        return $this->tca['columns'];
755
-    }
756
-
757
-    /**
758
-     * @return string
759
-     */
760
-    public function getCompositeField()
761
-    {
762
-        return $this->compositeField;
763
-    }
764
-
765
-    /**
766
-     * @param string $compositeField
767
-     */
768
-    public function setCompositeField($compositeField)
769
-    {
770
-        $this->compositeField = $compositeField;
771
-    }
772
-
773
-    /**
774
-     * Returns an instance of the Frontend object.
775
-     *
776
-     * @return TypoScriptFrontendController
777
-     */
778
-    protected function getFrontendObject()
779
-    {
780
-        return $GLOBALS['TSFE'];
781
-    }
21
+	/**
22
+	 * @var string
23
+	 */
24
+	protected $fieldName;
25
+
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $compositeField;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $tableName;
35
+
36
+	/**
37
+	 * @var array
38
+	 */
39
+	protected $tca;
40
+
41
+	/**
42
+	 * @param string $fieldName
43
+	 * @param array $tca
44
+	 * @param string $tableName
45
+	 * @param string $compositeField
46
+	 * @return \Fab\Vidi\Tca\FieldService
47
+	 */
48
+	public function __construct($fieldName, array $tca, $tableName, $compositeField = '')
49
+	{
50
+		$this->fieldName = $fieldName;
51
+		$this->tca = $tca;
52
+		$this->tableName = $tableName;
53
+		$this->compositeField = $compositeField;
54
+	}
55
+
56
+	/**
57
+	 * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc...
58
+	 *
59
+	 * @return bool
60
+	 */
61
+	public function isSystem()
62
+	{
63
+		return in_array($this->fieldName, Tca::getSystemFields());
64
+	}
65
+
66
+	/**
67
+	 * Tells the opposition of isSystem()
68
+	 *
69
+	 * @return bool
70
+	 */
71
+	public function isNotSystem()
72
+	{
73
+		return !$this->isSystem();
74
+	}
75
+
76
+	/**
77
+	 * Returns the configuration for a $field
78
+	 *
79
+	 * @throws \Exception
80
+	 * @return array
81
+	 */
82
+	public function getConfiguration()
83
+	{
84
+		return empty($this->tca['config']) ? [] : $this->tca['config'];
85
+	}
86
+
87
+	/**
88
+	 * Returns a key of the configuration.
89
+	 * If the key can not to be found, returns null.
90
+	 *
91
+	 * @param string $key
92
+	 * @return mixed
93
+	 */
94
+	public function get($key)
95
+	{
96
+		$configuration = $this->getConfiguration();
97
+		return empty($configuration[$key]) ? null : $configuration[$key];
98
+	}
99
+
100
+	/**
101
+	 * Returns the foreign field of a given field (opposite relational field).
102
+	 * If no relation exists, returns null.
103
+	 *
104
+	 * @return string|null
105
+	 */
106
+	public function getForeignField()
107
+	{
108
+		$result = null;
109
+		$configuration = $this->getConfiguration();
110
+
111
+		if (!empty($configuration['foreign_field'])) {
112
+			$result = $configuration['foreign_field'];
113
+		} elseif ($this->hasRelationManyToMany()) {
114
+			$foreignTable = $this->getForeignTable();
115
+			$manyToManyTable = $this->getManyToManyTable();
116
+
117
+			// Load TCA service of foreign field.
118
+			$tcaForeignTableService = Tca::table($foreignTable);
119
+
120
+			// Look into the MM relations checking for the opposite field
121
+			foreach ($tcaForeignTableService->getFields() as $fieldName) {
122
+				if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) {
123
+					$result = $fieldName;
124
+					break;
125
+				}
126
+			}
127
+		}
128
+		return $result;
129
+	}
130
+
131
+	/**
132
+	 * Returns the foreign table of a given field (opposite relational table).
133
+	 * If no relation exists, returns null.
134
+	 *
135
+	 * @return string|null
136
+	 */
137
+	public function getForeignTable()
138
+	{
139
+		$result = null;
140
+		$configuration = $this->getConfiguration();
141
+
142
+		if (!empty($configuration['foreign_table'])) {
143
+			$result = $configuration['foreign_table'];
144
+		} elseif ($this->isGroup()) {
145
+			$fieldParts = explode('.', $this->compositeField, 2);
146
+			$result = $fieldParts[1];
147
+		}
148
+		return $result;
149
+	}
150
+
151
+	/**
152
+	 * Returns the foreign clause.
153
+	 * If no foreign order exists, returns empty string.
154
+	 *
155
+	 * @return string
156
+	 */
157
+	public function getForeignClause()
158
+	{
159
+		$result = '';
160
+		$configuration = $this->getConfiguration();
161
+
162
+		if (!empty($configuration['foreign_table_where'])) {
163
+			$parts = explode('ORDER BY', $configuration['foreign_table_where']);
164
+			if (!empty($parts[0])) {
165
+				$result = $parts[0];
166
+			}
167
+		}
168
+
169
+		// Substitute some variables
170
+		return $this->substituteKnownMarkers($result);
171
+	}
172
+
173
+	/**
174
+	 * Substitute some known markers from the where clause in the Frontend Context.
175
+	 *
176
+	 * @param string $clause
177
+	 * @return string
178
+	 */
179
+	protected function substituteKnownMarkers($clause)
180
+	{
181
+		if ($clause && $this->isFrontendMode()) {
182
+			$searches = array(
183
+				'###CURRENT_PID###',
184
+				'###REC_FIELD_sys_language_uid###'
185
+			);
186
+
187
+			$replaces = array(
188
+				$this->getFrontendObject()->id,
189
+				GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'id'),
190
+			);
191
+
192
+			$clause = str_replace($searches, $replaces, $clause);
193
+		}
194
+		return $clause;
195
+	}
196
+
197
+	/**
198
+	 * Returns the foreign order of the current field.
199
+	 * If no foreign order exists, returns empty string.
200
+	 *
201
+	 * @return string
202
+	 */
203
+	public function getForeignOrder()
204
+	{
205
+		$result = '';
206
+		$configuration = $this->getConfiguration();
207
+
208
+		if (!empty($configuration['foreign_table_where'])) {
209
+			$parts = explode('ORDER BY', $configuration['foreign_table_where']);
210
+			if (!empty($parts[1])) {
211
+				$result = $parts[1];
212
+			}
213
+		}
214
+		return $result;
215
+	}
216
+
217
+	/**
218
+	 * Returns the MM table of a field.
219
+	 * If no relation exists, returns null.
220
+	 *
221
+	 * @return string|null
222
+	 */
223
+	public function getManyToManyTable()
224
+	{
225
+		$configuration = $this->getConfiguration();
226
+		return empty($configuration['MM']) ? null : $configuration['MM'];
227
+	}
228
+
229
+	/**
230
+	 * Returns a possible additional table name used in MM relations.
231
+	 * If no table name exists, returns null.
232
+	 *
233
+	 * @return string|null
234
+	 */
235
+	public function getAdditionalTableNameCondition()
236
+	{
237
+		$result = null;
238
+		$configuration = $this->getConfiguration();
239
+
240
+		if (!empty($configuration['MM_match_fields']['tablenames'])) {
241
+			$result = $configuration['MM_match_fields']['tablenames'];
242
+		} elseif ($this->isGroup()) {
243
+			// @todo check if $this->fieldName could be simply used as $result
244
+			$fieldParts = explode('.', $this->compositeField, 2);
245
+			$result = $fieldParts[1];
246
+		}
247
+
248
+		return $result;
249
+	}
250
+
251
+	/**
252
+	 * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc...
253
+	 *
254
+	 * @return array
255
+	 */
256
+	public function getAdditionalMMCondition()
257
+	{
258
+		$additionalMMConditions = [];
259
+		$configuration = $this->getConfiguration();
260
+
261
+		if (!empty($configuration['MM_match_fields'])) {
262
+			$additionalMMConditions = $configuration['MM_match_fields'];
263
+		}
264
+
265
+		// Add in any case a table name for "group"
266
+		if ($this->isGroup()) {
267
+			// @todo check if $this->fieldName could be simply used as $result
268
+			$fieldParts = explode('.', $this->compositeField, 2);
269
+			$additionalMMConditions = array(
270
+				'tablenames' => $fieldParts[1],
271
+			);
272
+		}
273
+		return $additionalMMConditions;
274
+	}
275
+
276
+	/**
277
+	 * Returns whether the field name is the opposite in MM relation.
278
+	 *
279
+	 * @return bool
280
+	 */
281
+	public function isOppositeRelation()
282
+	{
283
+		$configuration = $this->getConfiguration();
284
+		return isset($configuration['MM_opposite_field']);
285
+	}
286
+
287
+	/**
288
+	 * Returns the configuration for a $field.
289
+	 *
290
+	 * @throws \Exception
291
+	 * @return string
292
+	 */
293
+	public function getType()
294
+	{
295
+		if ($this->isSystem()) {
296
+			$fieldType = FieldType::NUMBER;
297
+		} else {
298
+			$configuration = $this->getConfiguration();
299
+
300
+			if (empty($configuration['type'])) {
301
+				throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627);
302
+			}
303
+
304
+			$fieldType = $configuration['type'];
305
+
306
+			if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) {
307
+				$fieldType = FieldType::MULTISELECT;
308
+			} elseif (!empty($configuration['foreign_table'])
309
+				&& ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file')
310
+			) {
311
+				$fieldType = FieldType::FILE;
312
+			} elseif (!empty($configuration['eval'])) {
313
+				$parts = GeneralUtility::trimExplode(',', $configuration['eval']);
314
+				if (in_array('datetime', $parts)) {
315
+					$fieldType = FieldType::DATETIME;
316
+				} elseif (in_array('date', $parts)) {
317
+					$fieldType = FieldType::DATE;
318
+				} elseif (in_array('email', $parts)) {
319
+					$fieldType = FieldType::EMAIL;
320
+				} elseif (in_array('int', $parts) || in_array('double2', $parts)) {
321
+					$fieldType = FieldType::NUMBER;
322
+				}
323
+			}
324
+
325
+			// Do some legacy conversion
326
+			if ($fieldType === 'input') {
327
+				$fieldType = FieldType::TEXT;
328
+			} elseif ($fieldType === 'text') {
329
+				$fieldType = FieldType::TEXTAREA;
330
+			}
331
+		}
332
+		return $fieldType;
333
+	}
334
+
335
+	/**
336
+	 * Return the default value.
337
+	 *
338
+	 * @return bool
339
+	 */
340
+	public function getDefaultValue()
341
+	{
342
+		$configuration = $this->getConfiguration();
343
+		return isset($configuration['default']) ? $configuration['default'] : null;
344
+	}
345
+
346
+	/**
347
+	 * Get the translation of a label given a column.
348
+	 *
349
+	 * @return string
350
+	 */
351
+	public function getLabel()
352
+	{
353
+		$label = '';
354
+		if ($this->hasLabel()) {
355
+			try {
356
+				$label = LocalizationUtility::translate($this->tca['label'], '');
357
+			} catch (\InvalidArgumentException $e) {
358
+			}
359
+			if (empty($label)) {
360
+				$label = $this->tca['label'];
361
+			}
362
+		}
363
+		return $label;
364
+	}
365
+
366
+	/**
367
+	 * Get the translation of a label given a column.
368
+	 *
369
+	 * @param string $itemValue the item value to search for.
370
+	 * @return string
371
+	 */
372
+	public function getLabelForItem($itemValue)
373
+	{
374
+		// Early return whether there is nothing to be translated as label.
375
+		if (is_null($itemValue)) {
376
+			return '';
377
+		} elseif (is_string($itemValue) && $itemValue === '') {
378
+			return $itemValue;
379
+		}
380
+
381
+		$configuration = $this->getConfiguration();
382
+		if (!empty($configuration['items']) && is_array($configuration['items'])) {
383
+			foreach ($configuration['items'] as $item) {
384
+				if ($item[1] == $itemValue) {
385
+					try {
386
+						$label = LocalizationUtility::translate($item[0], '');
387
+					} catch (\InvalidArgumentException $e) {
388
+					}
389
+					if (empty($label)) {
390
+						$label = $item[0];
391
+					}
392
+					break;
393
+				}
394
+			}
395
+		}
396
+
397
+		// Try fetching a label from a possible itemsProcFunc
398
+		if (!isset($label) && is_scalar($itemValue)) {
399
+			$items = $this->fetchItemsFromUserFunction();
400
+			if (!empty($items[$itemValue])) {
401
+				$label = $items[$itemValue];
402
+			}
403
+		}
404
+
405
+		// Returns a label if it has been found, otherwise returns the item value as fallback.
406
+		return isset($label) ? $label : $itemValue;
407
+	}
408
+
409
+	/**
410
+	 * Retrieve items from User Function.
411
+	 *
412
+	 * @return array
413
+	 */
414
+	protected function fetchItemsFromUserFunction()
415
+	{
416
+		$values = [];
417
+
418
+		$configuration = $this->getConfiguration();
419
+		if (!empty($configuration['itemsProcFunc'])) {
420
+			$parts = explode('php:', $configuration['itemsProcFunc']);
421
+			if (!empty($parts[1])) {
422
+				list($class, $method) = explode('->', $parts[1]);
423
+
424
+				$parameters['items'] = [];
425
+				$object = GeneralUtility::makeInstance($class);
426
+				$object->$method($parameters);
427
+
428
+				foreach ($parameters['items'] as $items) {
429
+					$values[$items[1]] = $items[0];
430
+				}
431
+			}
432
+		}
433
+		return $values;
434
+	}
435
+
436
+	/**
437
+	 * Get a possible icon given a field name an an item.
438
+	 *
439
+	 * @param string $itemValue the item value to search for.
440
+	 * @return string
441
+	 */
442
+	public function getIconForItem($itemValue)
443
+	{
444
+		$result = '';
445
+		$configuration = $this->getConfiguration();
446
+		if (!empty($configuration['items']) && is_array($configuration['items'])) {
447
+			foreach ($configuration['items'] as $item) {
448
+				if ($item[1] == $itemValue) {
449
+					$result = empty($item[2]) ? '' : $item[2];
450
+					break;
451
+				}
452
+			}
453
+		}
454
+		return $result;
455
+	}
456
+
457
+	/**
458
+	 * Returns whether the field has a label.
459
+	 *
460
+	 * @return bool
461
+	 */
462
+	public function hasLabel()
463
+	{
464
+		return empty($this->tca['label']) ? false : true;
465
+	}
466
+
467
+	/**
468
+	 * Tell whether the current BE User has access to this field.
469
+	 *
470
+	 * @return bool
471
+	 */
472
+	public function hasAccess()
473
+	{
474
+		$hasAccess = true;
475
+		if ($this->isBackendMode()
476
+			&& Tca::table($this->tableName)->hasAccess()
477
+			&& isset($this->tca['exclude'])
478
+			&& $this->tca['exclude']
479
+		) {
480
+			$hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName);
481
+		}
482
+		return $hasAccess;
483
+	}
484
+
485
+	/**
486
+	 * Returns whether the field is numerical.
487
+	 *
488
+	 * @return bool
489
+	 */
490
+	public function isNumerical()
491
+	{
492
+		$result = $this->isSystem();
493
+		if ($result === false) {
494
+			$configuration = $this->getConfiguration();
495
+			$parts = [];
496
+			if (!empty($configuration['eval'])) {
497
+				$parts = GeneralUtility::trimExplode(',', $configuration['eval']);
498
+			}
499
+			$result = in_array('int', $parts) || in_array('float', $parts);
500
+		}
501
+		return $result;
502
+	}
503
+
504
+	/**
505
+	 * Returns whether the field is of type text area.
506
+	 *
507
+	 * @return bool
508
+	 */
509
+	public function isTextArea()
510
+	{
511
+		return $this->getType() === FieldType::TEXTAREA;
512
+	}
513
+	/**
514
+	 * Returns whether the field is of type text area.
515
+	 *
516
+	 * @return bool
517
+	 */
518
+	public function isText()
519
+	{
520
+		return $this->getType() === FieldType::TEXT;
521
+	}
522
+
523
+	/**
524
+	 * Returns whether the field is displayed as a tree.
525
+	 *
526
+	 * @return bool
527
+	 */
528
+	public function isRenderModeTree()
529
+	{
530
+		$configuration = $this->getConfiguration();
531
+		return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE;
532
+	}
533
+
534
+	/**
535
+	 * Returns whether the field is of type select.
536
+	 *
537
+	 * @return bool
538
+	 */
539
+	public function isSelect()
540
+	{
541
+		return $this->getType() === FieldType::SELECT;
542
+	}
543
+
544
+	/**
545
+	 * Returns whether the field is of type select.
546
+	 *
547
+	 * @return bool
548
+	 */
549
+	public function isMultipleSelect()
550
+	{
551
+		return $this->getType() === FieldType::MULTISELECT;
552
+	}
553
+
554
+	/**
555
+	 * Returns whether the field is of type select.
556
+	 *
557
+	 * @return bool
558
+	 */
559
+	public function isCheckBox()
560
+	{
561
+		return $this->getType() === FieldType::CHECKBOX;
562
+	}
563
+
564
+	/**
565
+	 * Returns whether the field is of type db.
566
+	 *
567
+	 * @return bool
568
+	 */
569
+	public function isGroup()
570
+	{
571
+		return $this->getType() === 'group';
572
+	}
573
+
574
+	/**
575
+	 * Returns whether the field is language aware.
576
+	 *
577
+	 * @return bool
578
+	 */
579
+	public function isLocalized()
580
+	{
581
+		$isLocalized = false;
582
+		if (isset($this->tca['l10n_mode'])) {
583
+			if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') {
584
+				$isLocalized = true;
585
+			}
586
+		}
587
+		return $isLocalized;
588
+	}
589
+
590
+	/**
591
+	 * Returns whether the field is required.
592
+	 *
593
+	 * @return bool
594
+	 */
595
+	public function isRequired()
596
+	{
597
+		$configuration = $this->getConfiguration();
598
+
599
+		$isRequired = false;
600
+		if (isset($configuration['minitems'])) {
601
+			// is required of a select?
602
+			$isRequired = $configuration['minitems'] == 1 ? true : false;
603
+		} elseif (isset($configuration['eval'])) {
604
+			$parts = GeneralUtility::trimExplode(',', $configuration['eval'], true);
605
+			$isRequired = in_array('required', $parts);
606
+		}
607
+		return $isRequired;
608
+	}
609
+
610
+	/**
611
+	 * Returns an array containing the configuration of a column.
612
+	 *
613
+	 * @return array
614
+	 */
615
+	public function getField()
616
+	{
617
+		return $this->tca;
618
+	}
619
+
620
+	/**
621
+	 * Returns the relation type
622
+	 *
623
+	 * @return string
624
+	 */
625
+	public function relationDataType()
626
+	{
627
+		$configuration = $this->getConfiguration();
628
+		return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table'];
629
+	}
630
+
631
+	/**
632
+	 * Returns whether the field has relation (one to many, many to many)
633
+	 *
634
+	 * @return bool
635
+	 */
636
+	public function hasRelation()
637
+	{
638
+		return null !== $this->getForeignTable();
639
+	}
640
+
641
+	/**
642
+	 * Returns whether the field has no relation (one to many, many to many)
643
+	 *
644
+	 * @return bool
645
+	 */
646
+	public function hasNoRelation()
647
+	{
648
+		return !$this->hasRelation();
649
+	}
650
+
651
+	/**
652
+	 * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many".
653
+	 *
654
+	 * @return bool
655
+	 */
656
+	public function hasMany()
657
+	{
658
+		$configuration = $this->getConfiguration();
659
+		return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field']));
660
+	}
661
+
662
+	/**
663
+	 * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one".
664
+	 *
665
+	 * @return bool
666
+	 */
667
+	public function hasOne()
668
+	{
669
+		$configuration = $this->getConfiguration();
670
+		return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems']));
671
+	}
672
+
673
+	/**
674
+	 * Returns whether the field has many-to-one relation.
675
+	 *
676
+	 * @return bool
677
+	 */
678
+	public function hasRelationManyToOne()
679
+	{
680
+		$result = false;
681
+
682
+		$foreignField = $this->getForeignField();
683
+		if (!empty($foreignField)) {
684
+			// Load TCA service of the foreign field.
685
+			$foreignTable = $this->getForeignTable();
686
+			$result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany();
687
+		}
688
+		return $result;
689
+	}
690
+
691
+	/**
692
+	 * Returns whether the field has one-to-many relation.
693
+	 *
694
+	 * @return bool
695
+	 */
696
+	public function hasRelationOneToMany()
697
+	{
698
+		$result = false;
699
+
700
+		$foreignField = $this->getForeignField();
701
+		if (!empty($foreignField)) {
702
+			// Load TCA service of the foreign field.
703
+			$foreignTable = $this->getForeignTable();
704
+			$result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne();
705
+		}
706
+		return $result;
707
+	}
708
+
709
+	/**
710
+	 * Returns whether the field has one-to-one relation.
711
+	 *
712
+	 * @return bool
713
+	 */
714
+	public function hasRelationOneToOne()
715
+	{
716
+		$result = false;
717
+
718
+		$foreignField = $this->getForeignField();
719
+		if (!empty($foreignField)) {
720
+			// Load TCA service of foreign field.
721
+			$foreignTable = $this->getForeignTable();
722
+			$result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne();
723
+		}
724
+		return $result;
725
+	}
726
+
727
+	/**
728
+	 * Returns whether the field has many to many relation.
729
+	 *
730
+	 * @return bool
731
+	 */
732
+	public function hasRelationManyToMany()
733
+	{
734
+		$configuration = $this->getConfiguration();
735
+		return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field']));
736
+	}
737
+
738
+	/**
739
+	 * Returns whether the field has many to many relation using comma separated values (legacy).
740
+	 *
741
+	 * @return bool
742
+	 */
743
+	public function hasRelationWithCommaSeparatedValues()
744
+	{
745
+		$configuration = $this->getConfiguration();
746
+		return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1;
747
+	}
748
+
749
+	/**
750
+	 * @return array
751
+	 */
752
+	public function getTca()
753
+	{
754
+		return $this->tca['columns'];
755
+	}
756
+
757
+	/**
758
+	 * @return string
759
+	 */
760
+	public function getCompositeField()
761
+	{
762
+		return $this->compositeField;
763
+	}
764
+
765
+	/**
766
+	 * @param string $compositeField
767
+	 */
768
+	public function setCompositeField($compositeField)
769
+	{
770
+		$this->compositeField = $compositeField;
771
+	}
772
+
773
+	/**
774
+	 * Returns an instance of the Frontend object.
775
+	 *
776
+	 * @return TypoScriptFrontendController
777
+	 */
778
+	protected function getFrontendObject()
779
+	{
780
+		return $GLOBALS['TSFE'];
781
+	}
782 782
 }
Please login to merge, or discard this patch.
Classes/Tca/GridService.php 1 patch
Indentation   +691 added lines, -691 removed lines patch added patch discarded remove patch
@@ -23,695 +23,695 @@
 block discarded – undo
23 23
  */
24 24
 class GridService extends AbstractTca
25 25
 {
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $tca;
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $tableName;
35
-
36
-    /**
37
-     * All fields available in the Grid.
38
-     *
39
-     * @var array
40
-     */
41
-    protected $fields;
42
-
43
-    /**
44
-     * All fields regardless whether they have been excluded or not.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $allFields;
49
-
50
-    /**
51
-     * @var array
52
-     */
53
-    protected $instances;
54
-
55
-    /**
56
-     * @var array
57
-     */
58
-    protected $facets;
59
-
60
-    /**
61
-     * __construct
62
-     *
63
-     * @param string $tableName
64
-     */
65
-    public function __construct($tableName)
66
-    {
67
-        $this->tableName = $tableName;
68
-
69
-        if (empty($GLOBALS['TCA'][$this->tableName])) {
70
-            throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108);
71
-        }
72
-
73
-        $this->tca = $GLOBALS['TCA'][$this->tableName]['grid'] ?? [];
74
-    }
75
-
76
-    /**
77
-     * Returns an array containing column names.
78
-     *
79
-     * @return array
80
-     */
81
-    public function getFieldNames(): array
82
-    {
83
-        $fields = $this->getFields();
84
-        return array_keys($fields) ?: [];
85
-    }
86
-
87
-    /**
88
-     * Returns an array containing column names.
89
-     *
90
-     * @return array
91
-     */
92
-    public function getAllFieldNames(): array
93
-    {
94
-        $allFields = $this->getAllFields();
95
-        return array_keys($allFields);
96
-    }
97
-
98
-    /**
99
-     * Get the label key.
100
-     *
101
-     * @param string $fieldNameAndPath
102
-     * @return string
103
-     */
104
-    public function getLabelKey($fieldNameAndPath): string
105
-    {
106
-        $field = $this->getField($fieldNameAndPath);
107
-
108
-        // First option is to get the label from the Grid TCA.
109
-        $rawLabel = '';
110
-        if (isset($field['label'])) {
111
-            $rawLabel = $field['label'];
112
-        }
113
-
114
-        // Second option is to fetch the label from the Column Renderer object.
115
-        if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) {
116
-            $renderers = $this->getRenderers($fieldNameAndPath);
117
-            /** @var $renderer ColumnRendererInterface */
118
-            foreach ($renderers as $renderer) {
119
-                if (isset($renderer['label'])) {
120
-                    $rawLabel = $renderer['label'];
121
-                    break;
122
-                }
123
-            }
124
-        }
125
-        return $rawLabel;
126
-    }
127
-
128
-    /**
129
-     * Get the translation of a label given a column name.
130
-     *
131
-     * @param string $fieldNameAndPath
132
-     * @return string
133
-     */
134
-    public function getLabel($fieldNameAndPath)
135
-    {
136
-        $label = '';
137
-        if ($this->hasLabel($fieldNameAndPath)) {
138
-            $labelKey = $this->getLabelKey($fieldNameAndPath);
139
-            try {
140
-                $label = $this->getLanguageService()->sL($labelKey);
141
-            } catch (\InvalidArgumentException $e) {
142
-            }
143
-            if (empty($label)) {
144
-                $label = $labelKey;
145
-            }
146
-        } else {
147
-            // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved.
148
-            $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName);
149
-            $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName);
150
-            $table = Tca::table($dataType);
151
-
152
-            if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) {
153
-                $label = $table->field($fieldName)->getLabel();
154
-            }
155
-        }
156
-
157
-        return $label;
158
-    }
159
-
160
-    /**
161
-     * Returns the field name given its position.
162
-     *
163
-     * @param string $position the position of the field in the grid
164
-     * @return string
165
-     */
166
-    public function getFieldNameByPosition($position): string
167
-    {
168
-        $fields = array_keys($this->getFields());
169
-        if (empty($fields[$position])) {
170
-            throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119);
171
-        }
172
-
173
-        return (string)$fields[$position];
174
-    }
175
-
176
-    /**
177
-     * Returns a field name.
178
-     *
179
-     * @param string $fieldName
180
-     * @return array
181
-     */
182
-    public function getField($fieldName): array
183
-    {
184
-        $fields = $this->getFields();
185
-        return $fields[$fieldName] ?: [];
186
-    }
187
-
188
-    /**
189
-     * Returns an array containing column names for the Grid.
190
-     *
191
-     * @return array
192
-     */
193
-    public function getFields(): array
194
-    {
195
-        // Cache this operation since it can take some time.
196
-        if ($this->fields === null) {
197
-            // Fetch all available fields first.
198
-            $fields = $this->getAllFields();
199
-
200
-            if ($this->isBackendMode()) {
201
-                // Then remove the not allowed.
202
-                $fields = $this->filterByIncludedFields($fields);
203
-                $fields = $this->filterByBackendUser($fields);
204
-                $fields = $this->filterByExcludedFields($fields);
205
-            }
206
-
207
-            $this->fields = $fields;
208
-        }
209
-
210
-        return $this->fields;
211
-    }
212
-
213
-    /**
214
-     * Remove fields according to Grid configuration.
215
-     *
216
-     * @param $fields
217
-     * @return array
218
-     */
219
-    protected function filterByIncludedFields($fields): array
220
-    {
221
-        $filteredFields = $fields;
222
-        $includedFields = $this->getIncludedFields();
223
-        if (count($includedFields) > 0) {
224
-            $filteredFields = [];
225
-            foreach ($fields as $fieldNameAndPath => $configuration) {
226
-                if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) {
227
-                    $filteredFields[$fieldNameAndPath] = $configuration;
228
-                }
229
-            }
230
-        }
231
-        return $filteredFields;
232
-    }
233
-
234
-    /**
235
-     * Remove fields according to BE User permission.
236
-     *
237
-     * @param $fields
238
-     * @return array
239
-     */
240
-    protected function filterByBackendUser($fields): array
241
-    {
242
-        if (!$this->getBackendUser()->isAdmin()) {
243
-            foreach ($fields as $fieldName => $field) {
244
-                if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) {
245
-                    unset($fields[$fieldName]);
246
-                }
247
-            }
248
-        }
249
-        return $fields;
250
-    }
251
-
252
-    /**
253
-     * Remove fields according to Grid configuration.
254
-     *
255
-     * @param $fields
256
-     * @return array
257
-     */
258
-    protected function filterByExcludedFields($fields): array
259
-    {
260
-        // Unset excluded fields.
261
-        foreach ($this->getExcludedFields() as $excludedField) {
262
-            if (isset($fields[$excludedField])) {
263
-                unset($fields[$excludedField]);
264
-            }
265
-        }
266
-
267
-        return $fields;
268
-    }
269
-
270
-    /**
271
-     * Returns an array containing column names for the Grid.
272
-     *
273
-     * @return array
274
-     */
275
-    public function getAllFields(): array
276
-    {
277
-        // Cache this operation since it can take some time.
278
-        if ($this->allFields === null) {
279
-            $fields = isset($this->tca['columns']) && is_array($this->tca['columns']) ? $this->tca['columns'] : [];
280
-            $gridFieldNames = array_keys($fields);
281
-
282
-            // Fetch all fields of the TCA and merge it back to the fields configured for Grid.
283
-            $tableFieldNames = Tca::table($this->tableName)->getFields();
284
-
285
-            // Just remove system fields from the Grid.
286
-            foreach ($tableFieldNames as $key => $fieldName) {
287
-                if (in_array($fieldName, Tca::getSystemFields())) {
288
-                    unset($tableFieldNames[$key]);
289
-                }
290
-            }
291
-
292
-            $additionalFields = array_diff($tableFieldNames, $gridFieldNames);
293
-
294
-            if (!empty($additionalFields)) {
295
-                // Pop out last element of the key
296
-                // Idea is to place new un-configured columns in between. By default, they will be hidden.
297
-                end($fields);
298
-                $lastColumnKey = key($fields);
299
-                $lastColumn = array_pop($fields);
300
-
301
-                // Feed up the grid fields with un configured elements
302
-                foreach ($additionalFields as $additionalField) {
303
-                    $fields[$additionalField] = array(
304
-                        'visible' => false
305
-                    );
306
-
307
-                    // Try to guess the format of the field.
308
-                    $fieldType = Tca::table($this->tableName)->field($additionalField)->getType();
309
-                    if ($fieldType === FieldType::DATE) {
310
-                        $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date';
311
-                    } elseif ($fieldType === FieldType::DATETIME) {
312
-                        $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime';
313
-                    }
314
-                }
315
-                $fields[$lastColumnKey] = $lastColumn;
316
-            }
317
-
318
-            $this->allFields = $fields;
319
-        }
320
-
321
-        return $this->allFields;
322
-    }
323
-
324
-    /**
325
-     * Tell whether the field exists in the grid or not.
326
-     *
327
-     * @param string $fieldName
328
-     * @return bool
329
-     */
330
-    public function hasField($fieldName): bool
331
-    {
332
-        $fields = $this->getFields();
333
-        return isset($fields[$fieldName]);
334
-    }
335
-
336
-    /**
337
-     * Tell whether the facet exists in the grid or not.
338
-     *
339
-     * @param string $facetName
340
-     * @return bool
341
-     */
342
-    public function hasFacet($facetName): bool
343
-    {
344
-        $facets = $this->getFacets();
345
-        return isset($facets[$facetName]);
346
-    }
347
-
348
-    /**
349
-     * Returns an array containing facets fields.
350
-     *
351
-     * @return FacetInterface[]
352
-     */
353
-    public function getFacets(): array
354
-    {
355
-        if ($this->facets === null) {
356
-            $this->facets = [];
357
-
358
-            if (is_array($this->tca['facets'])) {
359
-                foreach ($this->tca['facets'] as $key => $facetNameOrArray) {
360
-                    if (is_array($facetNameOrArray)) {
361
-                        $name = $facetNameOrArray['name'] ?? '';
362
-
363
-                        $label = isset($facetNameOrArray['label'])
364
-                            ? $this->getLanguageService()->sL($facetNameOrArray['label'])
365
-                            : '';
366
-
367
-                        $suggestions = $facetNameOrArray['suggestions'] ?? [];
368
-                        $configuration = $facetNameOrArray['configuration'] ?? [];
369
-
370
-                        /** @var FacetInterface $facetObject */
371
-                        $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration);
372
-                        $this->facets[$facetObject->getName()] = $facetObject;
373
-                    } else {
374
-                        $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray);
375
-                    }
376
-                }
377
-            }
378
-        }
379
-        return $this->facets;
380
-    }
381
-
382
-    /**
383
-     * Returns the "sortable" value of the column.
384
-     *
385
-     * @param string $fieldName
386
-     * @return int|string
387
-     */
388
-    public function isSortable($fieldName)
389
-    {
390
-        $defaultValue = true;
391
-        $hasSortableField = Tca::table($this->tableName)->hasSortableField();
392
-        if ($hasSortableField) {
393
-            $isSortable = false;
394
-        } else {
395
-            $isSortable = $this->get($fieldName, 'sortable', $defaultValue);
396
-        }
397
-        return $isSortable;
398
-    }
399
-
400
-    /**
401
-     * Returns the "canBeHidden" value of the column.
402
-     *
403
-     * @param string $fieldName
404
-     * @return bool
405
-     */
406
-    public function canBeHidden($fieldName): bool
407
-    {
408
-        $defaultValue = true;
409
-        return $this->get($fieldName, 'canBeHidden', $defaultValue);
410
-    }
411
-
412
-    /**
413
-     * Returns the "width" value of the column.
414
-     *
415
-     * @param string $fieldName
416
-     * @return int|string
417
-     */
418
-    public function getWidth($fieldName)
419
-    {
420
-        $defaultValue = 'auto';
421
-        return $this->get($fieldName, 'width', $defaultValue);
422
-    }
423
-
424
-    /**
425
-     * Returns the "visible" value of the column.
426
-     *
427
-     * @param string $fieldName
428
-     * @return bool
429
-     */
430
-    public function isVisible($fieldName): bool
431
-    {
432
-        $defaultValue = true;
433
-        return $this->get($fieldName, 'visible', $defaultValue);
434
-    }
435
-
436
-    /**
437
-     * Returns the "editable" value of the column.
438
-     *
439
-     * @param string $columnName
440
-     * @return bool
441
-     */
442
-    public function isEditable($columnName): bool
443
-    {
444
-        $defaultValue = false;
445
-        return $this->get($columnName, 'editable', $defaultValue);
446
-    }
447
-
448
-    /**
449
-     * Returns the "localized" value of the column.
450
-     *
451
-     * @param string $columnName
452
-     * @return bool
453
-     */
454
-    public function isLocalized($columnName): bool
455
-    {
456
-        $defaultValue = true;
457
-        return $this->get($columnName, 'localized', $defaultValue);
458
-    }
459
-
460
-    /**
461
-     *
462
-     * Returns the "html" value of the column.
463
-     *
464
-     * @param string $fieldName
465
-     * @return string
466
-     */
467
-    public function getHeader($fieldName): string
468
-    {
469
-        $defaultValue = '';
470
-        return $this->get($fieldName, 'html', $defaultValue);
471
-    }
472
-
473
-    /**
474
-     * Fetch a possible from a Grid Renderer. If no value is found, returns null
475
-     *
476
-     * @param string $fieldName
477
-     * @param string $key
478
-     * @param mixed $defaultValue
479
-     * @return null|mixed
480
-     */
481
-    public function get($fieldName, $key, $defaultValue = null)
482
-    {
483
-        $value = $defaultValue;
484
-
485
-        $field = $this->getField($fieldName);
486
-        if (isset($field[$key])) {
487
-            $value = $field[$key];
488
-        } elseif ($this->hasRenderers($fieldName)) {
489
-            $renderers = $this->getRenderers($fieldName);
490
-            foreach ($renderers as $rendererConfiguration) {
491
-                if (isset($rendererConfiguration[$key])) {
492
-                    $value = $rendererConfiguration[$key];
493
-                }
494
-            }
495
-        }
496
-        return $value;
497
-    }
498
-
499
-    /**
500
-     * Returns whether the column has a renderer.
501
-     *
502
-     * @param string $fieldName
503
-     * @return bool
504
-     */
505
-    public function hasRenderers($fieldName): bool
506
-    {
507
-        $field = $this->getField($fieldName);
508
-        return empty($field['renderer']) && empty($field['renderers']) ? false : true;
509
-    }
510
-
511
-    /**
512
-     * Returns a renderer.
513
-     *
514
-     * @param string $fieldName
515
-     * @return array
516
-     */
517
-    public function getRenderers($fieldName): array
518
-    {
519
-        $field = $this->getField($fieldName);
520
-        $renderers = [];
521
-        if (!empty($field['renderer'])) {
522
-            $renderers = $this->convertRendererToArray($field['renderer'], $field);
523
-        } elseif (!empty($field['renderers']) && is_array($field['renderers'])) {
524
-            foreach ($field['renderers'] as $renderer) {
525
-                $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field);
526
-                $renderers = array_merge($renderers, $rendererNameAndConfiguration);
527
-            }
528
-        }
529
-
530
-        return $renderers;
531
-    }
532
-
533
-    /**
534
-     * @param string $renderer
535
-     * @return array
536
-     */
537
-    protected function convertRendererToArray($renderer, array $field): array
538
-    {
539
-        $result = [];
540
-        if (is_string($renderer)) {
541
-            $configuration = empty($field['rendererConfiguration'])
542
-                ? []
543
-                : $field['rendererConfiguration'];
544
-
545
-            /** @var ColumnRendererInterface $rendererObject */
546
-            $rendererObject = GeneralUtility::makeInstance($renderer);
547
-
548
-            $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration);
549
-        // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7
550
-        } elseif ($renderer instanceof ColumnRendererInterface) {
551
-            /** @var ColumnRendererInterface $renderer */
552
-            $result[get_class($renderer)] = $renderer->getConfiguration();
553
-        }
554
-        return $result;
555
-    }
556
-
557
-    /**
558
-     * Returns the class names applied to a cell
559
-     *
560
-     * @param string $fieldName
561
-     * @return bool
562
-     */
563
-    public function getClass($fieldName): bool
564
-    {
565
-        $field = $this->getField($fieldName);
566
-        return isset($field['class']) ? $field['class'] : '';
567
-    }
568
-
569
-    /**
570
-     * Returns whether the column has a label.
571
-     *
572
-     * @param string $fieldNameAndPath
573
-     * @return bool
574
-     */
575
-    public function hasLabel($fieldNameAndPath): bool
576
-    {
577
-        $field = $this->getField($fieldNameAndPath);
578
-
579
-        $hasLabel = empty($field['label']) ? false : true;
580
-
581
-        if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) {
582
-            $renderers = $this->getRenderers($fieldNameAndPath);
583
-            /** @var $renderer ColumnRendererInterface */
584
-            foreach ($renderers as $renderer) {
585
-                if (isset($renderer['label'])) {
586
-                    $hasLabel = true;
587
-                    break;
588
-                }
589
-            }
590
-        }
591
-        return $hasLabel;
592
-    }
593
-
594
-    /**
595
-     * @return array
596
-     */
597
-    public function getTca(): array
598
-    {
599
-        return $this->tca;
600
-    }
601
-
602
-    /**
603
-     * @return array
604
-     */
605
-    public function getIncludedFields(): array
606
-    {
607
-        return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true);
608
-    }
609
-
610
-    /**
611
-     * Return excluded fields from configuration + preferences.
612
-     *
613
-     * @return array
614
-     */
615
-    public function getExcludedFields(): array
616
-    {
617
-        $configurationFields = $this->getExcludedFieldsFromConfiguration();
618
-        $preferencesFields = $this->getExcludedFieldsFromPreferences();
619
-
620
-        return array_merge($configurationFields, $preferencesFields);
621
-    }
622
-
623
-    /**
624
-     * Fetch excluded fields from configuration.
625
-     *
626
-     * @return array
627
-     */
628
-    protected function getExcludedFieldsFromConfiguration(): array
629
-    {
630
-        $excludedFields = [];
631
-        if (!empty($this->tca['excluded_fields'])) {
632
-            $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true);
633
-        } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason.
634
-            $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true);
635
-        }
636
-        return $excludedFields;
637
-    }
638
-
639
-    /**
640
-     * Fetch excluded fields from preferences.
641
-     *
642
-     * @return array
643
-     */
644
-    protected function getExcludedFieldsFromPreferences(): array
645
-    {
646
-        $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName);
647
-        return is_array($excludedFields) ? $excludedFields : [];
648
-    }
649
-
650
-    /**
651
-     * @return bool
652
-     */
653
-    public function areFilesIncludedInExport(): bool
654
-    {
655
-        $isIncluded = true;
656
-
657
-        if (isset($this->tca['export']['include_files'])) {
658
-            $isIncluded = (bool)$this->tca['export']['include_files'];
659
-        }
660
-        return $isIncluded;
661
-    }
662
-
663
-    /**
664
-     * Returns a "facet" service instance.
665
-     *
666
-     * @param string|FacetInterface $facetName
667
-     * @return StandardFacet
668
-     */
669
-    protected function instantiateStandardFacet($facetName): StandardFacet
670
-    {
671
-        $label = $this->getLabel($facetName);
672
-
673
-        /** @var StandardFacet $facetName */
674
-        $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label);
675
-
676
-        if (!$facet instanceof StandardFacet) {
677
-            throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345);
678
-        }
679
-        return $facet;
680
-    }
681
-
682
-    /**
683
-     * Returns a "facet" service instance.
684
-     *
685
-     * @param string|FacetInterface $facetName
686
-     * @return FacetInterface
687
-     */
688
-    public function facet($facetName = ''): FacetInterface
689
-    {
690
-        $facets = $this->getFacets();
691
-        return $facets[$facetName];
692
-    }
693
-
694
-    /**
695
-     * @return FieldPathResolver|object
696
-     */
697
-    protected function getFieldPathResolver()
698
-    {
699
-        return GeneralUtility::makeInstance(FieldPathResolver::class);
700
-    }
701
-
702
-    /**
703
-     * @return ModulePreferences|object
704
-     */
705
-    protected function getModulePreferences()
706
-    {
707
-        return GeneralUtility::makeInstance(ModulePreferences::class);
708
-    }
709
-
710
-    /**
711
-     * @return LanguageService|object
712
-     */
713
-    protected function getLanguageService()
714
-    {
715
-        return GeneralUtility::makeInstance(LanguageService::class);
716
-    }
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $tca;
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $tableName;
35
+
36
+	/**
37
+	 * All fields available in the Grid.
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $fields;
42
+
43
+	/**
44
+	 * All fields regardless whether they have been excluded or not.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $allFields;
49
+
50
+	/**
51
+	 * @var array
52
+	 */
53
+	protected $instances;
54
+
55
+	/**
56
+	 * @var array
57
+	 */
58
+	protected $facets;
59
+
60
+	/**
61
+	 * __construct
62
+	 *
63
+	 * @param string $tableName
64
+	 */
65
+	public function __construct($tableName)
66
+	{
67
+		$this->tableName = $tableName;
68
+
69
+		if (empty($GLOBALS['TCA'][$this->tableName])) {
70
+			throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108);
71
+		}
72
+
73
+		$this->tca = $GLOBALS['TCA'][$this->tableName]['grid'] ?? [];
74
+	}
75
+
76
+	/**
77
+	 * Returns an array containing column names.
78
+	 *
79
+	 * @return array
80
+	 */
81
+	public function getFieldNames(): array
82
+	{
83
+		$fields = $this->getFields();
84
+		return array_keys($fields) ?: [];
85
+	}
86
+
87
+	/**
88
+	 * Returns an array containing column names.
89
+	 *
90
+	 * @return array
91
+	 */
92
+	public function getAllFieldNames(): array
93
+	{
94
+		$allFields = $this->getAllFields();
95
+		return array_keys($allFields);
96
+	}
97
+
98
+	/**
99
+	 * Get the label key.
100
+	 *
101
+	 * @param string $fieldNameAndPath
102
+	 * @return string
103
+	 */
104
+	public function getLabelKey($fieldNameAndPath): string
105
+	{
106
+		$field = $this->getField($fieldNameAndPath);
107
+
108
+		// First option is to get the label from the Grid TCA.
109
+		$rawLabel = '';
110
+		if (isset($field['label'])) {
111
+			$rawLabel = $field['label'];
112
+		}
113
+
114
+		// Second option is to fetch the label from the Column Renderer object.
115
+		if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) {
116
+			$renderers = $this->getRenderers($fieldNameAndPath);
117
+			/** @var $renderer ColumnRendererInterface */
118
+			foreach ($renderers as $renderer) {
119
+				if (isset($renderer['label'])) {
120
+					$rawLabel = $renderer['label'];
121
+					break;
122
+				}
123
+			}
124
+		}
125
+		return $rawLabel;
126
+	}
127
+
128
+	/**
129
+	 * Get the translation of a label given a column name.
130
+	 *
131
+	 * @param string $fieldNameAndPath
132
+	 * @return string
133
+	 */
134
+	public function getLabel($fieldNameAndPath)
135
+	{
136
+		$label = '';
137
+		if ($this->hasLabel($fieldNameAndPath)) {
138
+			$labelKey = $this->getLabelKey($fieldNameAndPath);
139
+			try {
140
+				$label = $this->getLanguageService()->sL($labelKey);
141
+			} catch (\InvalidArgumentException $e) {
142
+			}
143
+			if (empty($label)) {
144
+				$label = $labelKey;
145
+			}
146
+		} else {
147
+			// Important to notice the label can contains a path, e.g. metadata.categories and must be resolved.
148
+			$dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName);
149
+			$fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName);
150
+			$table = Tca::table($dataType);
151
+
152
+			if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) {
153
+				$label = $table->field($fieldName)->getLabel();
154
+			}
155
+		}
156
+
157
+		return $label;
158
+	}
159
+
160
+	/**
161
+	 * Returns the field name given its position.
162
+	 *
163
+	 * @param string $position the position of the field in the grid
164
+	 * @return string
165
+	 */
166
+	public function getFieldNameByPosition($position): string
167
+	{
168
+		$fields = array_keys($this->getFields());
169
+		if (empty($fields[$position])) {
170
+			throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119);
171
+		}
172
+
173
+		return (string)$fields[$position];
174
+	}
175
+
176
+	/**
177
+	 * Returns a field name.
178
+	 *
179
+	 * @param string $fieldName
180
+	 * @return array
181
+	 */
182
+	public function getField($fieldName): array
183
+	{
184
+		$fields = $this->getFields();
185
+		return $fields[$fieldName] ?: [];
186
+	}
187
+
188
+	/**
189
+	 * Returns an array containing column names for the Grid.
190
+	 *
191
+	 * @return array
192
+	 */
193
+	public function getFields(): array
194
+	{
195
+		// Cache this operation since it can take some time.
196
+		if ($this->fields === null) {
197
+			// Fetch all available fields first.
198
+			$fields = $this->getAllFields();
199
+
200
+			if ($this->isBackendMode()) {
201
+				// Then remove the not allowed.
202
+				$fields = $this->filterByIncludedFields($fields);
203
+				$fields = $this->filterByBackendUser($fields);
204
+				$fields = $this->filterByExcludedFields($fields);
205
+			}
206
+
207
+			$this->fields = $fields;
208
+		}
209
+
210
+		return $this->fields;
211
+	}
212
+
213
+	/**
214
+	 * Remove fields according to Grid configuration.
215
+	 *
216
+	 * @param $fields
217
+	 * @return array
218
+	 */
219
+	protected function filterByIncludedFields($fields): array
220
+	{
221
+		$filteredFields = $fields;
222
+		$includedFields = $this->getIncludedFields();
223
+		if (count($includedFields) > 0) {
224
+			$filteredFields = [];
225
+			foreach ($fields as $fieldNameAndPath => $configuration) {
226
+				if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) {
227
+					$filteredFields[$fieldNameAndPath] = $configuration;
228
+				}
229
+			}
230
+		}
231
+		return $filteredFields;
232
+	}
233
+
234
+	/**
235
+	 * Remove fields according to BE User permission.
236
+	 *
237
+	 * @param $fields
238
+	 * @return array
239
+	 */
240
+	protected function filterByBackendUser($fields): array
241
+	{
242
+		if (!$this->getBackendUser()->isAdmin()) {
243
+			foreach ($fields as $fieldName => $field) {
244
+				if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) {
245
+					unset($fields[$fieldName]);
246
+				}
247
+			}
248
+		}
249
+		return $fields;
250
+	}
251
+
252
+	/**
253
+	 * Remove fields according to Grid configuration.
254
+	 *
255
+	 * @param $fields
256
+	 * @return array
257
+	 */
258
+	protected function filterByExcludedFields($fields): array
259
+	{
260
+		// Unset excluded fields.
261
+		foreach ($this->getExcludedFields() as $excludedField) {
262
+			if (isset($fields[$excludedField])) {
263
+				unset($fields[$excludedField]);
264
+			}
265
+		}
266
+
267
+		return $fields;
268
+	}
269
+
270
+	/**
271
+	 * Returns an array containing column names for the Grid.
272
+	 *
273
+	 * @return array
274
+	 */
275
+	public function getAllFields(): array
276
+	{
277
+		// Cache this operation since it can take some time.
278
+		if ($this->allFields === null) {
279
+			$fields = isset($this->tca['columns']) && is_array($this->tca['columns']) ? $this->tca['columns'] : [];
280
+			$gridFieldNames = array_keys($fields);
281
+
282
+			// Fetch all fields of the TCA and merge it back to the fields configured for Grid.
283
+			$tableFieldNames = Tca::table($this->tableName)->getFields();
284
+
285
+			// Just remove system fields from the Grid.
286
+			foreach ($tableFieldNames as $key => $fieldName) {
287
+				if (in_array($fieldName, Tca::getSystemFields())) {
288
+					unset($tableFieldNames[$key]);
289
+				}
290
+			}
291
+
292
+			$additionalFields = array_diff($tableFieldNames, $gridFieldNames);
293
+
294
+			if (!empty($additionalFields)) {
295
+				// Pop out last element of the key
296
+				// Idea is to place new un-configured columns in between. By default, they will be hidden.
297
+				end($fields);
298
+				$lastColumnKey = key($fields);
299
+				$lastColumn = array_pop($fields);
300
+
301
+				// Feed up the grid fields with un configured elements
302
+				foreach ($additionalFields as $additionalField) {
303
+					$fields[$additionalField] = array(
304
+						'visible' => false
305
+					);
306
+
307
+					// Try to guess the format of the field.
308
+					$fieldType = Tca::table($this->tableName)->field($additionalField)->getType();
309
+					if ($fieldType === FieldType::DATE) {
310
+						$fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date';
311
+					} elseif ($fieldType === FieldType::DATETIME) {
312
+						$fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime';
313
+					}
314
+				}
315
+				$fields[$lastColumnKey] = $lastColumn;
316
+			}
317
+
318
+			$this->allFields = $fields;
319
+		}
320
+
321
+		return $this->allFields;
322
+	}
323
+
324
+	/**
325
+	 * Tell whether the field exists in the grid or not.
326
+	 *
327
+	 * @param string $fieldName
328
+	 * @return bool
329
+	 */
330
+	public function hasField($fieldName): bool
331
+	{
332
+		$fields = $this->getFields();
333
+		return isset($fields[$fieldName]);
334
+	}
335
+
336
+	/**
337
+	 * Tell whether the facet exists in the grid or not.
338
+	 *
339
+	 * @param string $facetName
340
+	 * @return bool
341
+	 */
342
+	public function hasFacet($facetName): bool
343
+	{
344
+		$facets = $this->getFacets();
345
+		return isset($facets[$facetName]);
346
+	}
347
+
348
+	/**
349
+	 * Returns an array containing facets fields.
350
+	 *
351
+	 * @return FacetInterface[]
352
+	 */
353
+	public function getFacets(): array
354
+	{
355
+		if ($this->facets === null) {
356
+			$this->facets = [];
357
+
358
+			if (is_array($this->tca['facets'])) {
359
+				foreach ($this->tca['facets'] as $key => $facetNameOrArray) {
360
+					if (is_array($facetNameOrArray)) {
361
+						$name = $facetNameOrArray['name'] ?? '';
362
+
363
+						$label = isset($facetNameOrArray['label'])
364
+							? $this->getLanguageService()->sL($facetNameOrArray['label'])
365
+							: '';
366
+
367
+						$suggestions = $facetNameOrArray['suggestions'] ?? [];
368
+						$configuration = $facetNameOrArray['configuration'] ?? [];
369
+
370
+						/** @var FacetInterface $facetObject */
371
+						$facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration);
372
+						$this->facets[$facetObject->getName()] = $facetObject;
373
+					} else {
374
+						$this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray);
375
+					}
376
+				}
377
+			}
378
+		}
379
+		return $this->facets;
380
+	}
381
+
382
+	/**
383
+	 * Returns the "sortable" value of the column.
384
+	 *
385
+	 * @param string $fieldName
386
+	 * @return int|string
387
+	 */
388
+	public function isSortable($fieldName)
389
+	{
390
+		$defaultValue = true;
391
+		$hasSortableField = Tca::table($this->tableName)->hasSortableField();
392
+		if ($hasSortableField) {
393
+			$isSortable = false;
394
+		} else {
395
+			$isSortable = $this->get($fieldName, 'sortable', $defaultValue);
396
+		}
397
+		return $isSortable;
398
+	}
399
+
400
+	/**
401
+	 * Returns the "canBeHidden" value of the column.
402
+	 *
403
+	 * @param string $fieldName
404
+	 * @return bool
405
+	 */
406
+	public function canBeHidden($fieldName): bool
407
+	{
408
+		$defaultValue = true;
409
+		return $this->get($fieldName, 'canBeHidden', $defaultValue);
410
+	}
411
+
412
+	/**
413
+	 * Returns the "width" value of the column.
414
+	 *
415
+	 * @param string $fieldName
416
+	 * @return int|string
417
+	 */
418
+	public function getWidth($fieldName)
419
+	{
420
+		$defaultValue = 'auto';
421
+		return $this->get($fieldName, 'width', $defaultValue);
422
+	}
423
+
424
+	/**
425
+	 * Returns the "visible" value of the column.
426
+	 *
427
+	 * @param string $fieldName
428
+	 * @return bool
429
+	 */
430
+	public function isVisible($fieldName): bool
431
+	{
432
+		$defaultValue = true;
433
+		return $this->get($fieldName, 'visible', $defaultValue);
434
+	}
435
+
436
+	/**
437
+	 * Returns the "editable" value of the column.
438
+	 *
439
+	 * @param string $columnName
440
+	 * @return bool
441
+	 */
442
+	public function isEditable($columnName): bool
443
+	{
444
+		$defaultValue = false;
445
+		return $this->get($columnName, 'editable', $defaultValue);
446
+	}
447
+
448
+	/**
449
+	 * Returns the "localized" value of the column.
450
+	 *
451
+	 * @param string $columnName
452
+	 * @return bool
453
+	 */
454
+	public function isLocalized($columnName): bool
455
+	{
456
+		$defaultValue = true;
457
+		return $this->get($columnName, 'localized', $defaultValue);
458
+	}
459
+
460
+	/**
461
+	 *
462
+	 * Returns the "html" value of the column.
463
+	 *
464
+	 * @param string $fieldName
465
+	 * @return string
466
+	 */
467
+	public function getHeader($fieldName): string
468
+	{
469
+		$defaultValue = '';
470
+		return $this->get($fieldName, 'html', $defaultValue);
471
+	}
472
+
473
+	/**
474
+	 * Fetch a possible from a Grid Renderer. If no value is found, returns null
475
+	 *
476
+	 * @param string $fieldName
477
+	 * @param string $key
478
+	 * @param mixed $defaultValue
479
+	 * @return null|mixed
480
+	 */
481
+	public function get($fieldName, $key, $defaultValue = null)
482
+	{
483
+		$value = $defaultValue;
484
+
485
+		$field = $this->getField($fieldName);
486
+		if (isset($field[$key])) {
487
+			$value = $field[$key];
488
+		} elseif ($this->hasRenderers($fieldName)) {
489
+			$renderers = $this->getRenderers($fieldName);
490
+			foreach ($renderers as $rendererConfiguration) {
491
+				if (isset($rendererConfiguration[$key])) {
492
+					$value = $rendererConfiguration[$key];
493
+				}
494
+			}
495
+		}
496
+		return $value;
497
+	}
498
+
499
+	/**
500
+	 * Returns whether the column has a renderer.
501
+	 *
502
+	 * @param string $fieldName
503
+	 * @return bool
504
+	 */
505
+	public function hasRenderers($fieldName): bool
506
+	{
507
+		$field = $this->getField($fieldName);
508
+		return empty($field['renderer']) && empty($field['renderers']) ? false : true;
509
+	}
510
+
511
+	/**
512
+	 * Returns a renderer.
513
+	 *
514
+	 * @param string $fieldName
515
+	 * @return array
516
+	 */
517
+	public function getRenderers($fieldName): array
518
+	{
519
+		$field = $this->getField($fieldName);
520
+		$renderers = [];
521
+		if (!empty($field['renderer'])) {
522
+			$renderers = $this->convertRendererToArray($field['renderer'], $field);
523
+		} elseif (!empty($field['renderers']) && is_array($field['renderers'])) {
524
+			foreach ($field['renderers'] as $renderer) {
525
+				$rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field);
526
+				$renderers = array_merge($renderers, $rendererNameAndConfiguration);
527
+			}
528
+		}
529
+
530
+		return $renderers;
531
+	}
532
+
533
+	/**
534
+	 * @param string $renderer
535
+	 * @return array
536
+	 */
537
+	protected function convertRendererToArray($renderer, array $field): array
538
+	{
539
+		$result = [];
540
+		if (is_string($renderer)) {
541
+			$configuration = empty($field['rendererConfiguration'])
542
+				? []
543
+				: $field['rendererConfiguration'];
544
+
545
+			/** @var ColumnRendererInterface $rendererObject */
546
+			$rendererObject = GeneralUtility::makeInstance($renderer);
547
+
548
+			$result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration);
549
+		// TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7
550
+		} elseif ($renderer instanceof ColumnRendererInterface) {
551
+			/** @var ColumnRendererInterface $renderer */
552
+			$result[get_class($renderer)] = $renderer->getConfiguration();
553
+		}
554
+		return $result;
555
+	}
556
+
557
+	/**
558
+	 * Returns the class names applied to a cell
559
+	 *
560
+	 * @param string $fieldName
561
+	 * @return bool
562
+	 */
563
+	public function getClass($fieldName): bool
564
+	{
565
+		$field = $this->getField($fieldName);
566
+		return isset($field['class']) ? $field['class'] : '';
567
+	}
568
+
569
+	/**
570
+	 * Returns whether the column has a label.
571
+	 *
572
+	 * @param string $fieldNameAndPath
573
+	 * @return bool
574
+	 */
575
+	public function hasLabel($fieldNameAndPath): bool
576
+	{
577
+		$field = $this->getField($fieldNameAndPath);
578
+
579
+		$hasLabel = empty($field['label']) ? false : true;
580
+
581
+		if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) {
582
+			$renderers = $this->getRenderers($fieldNameAndPath);
583
+			/** @var $renderer ColumnRendererInterface */
584
+			foreach ($renderers as $renderer) {
585
+				if (isset($renderer['label'])) {
586
+					$hasLabel = true;
587
+					break;
588
+				}
589
+			}
590
+		}
591
+		return $hasLabel;
592
+	}
593
+
594
+	/**
595
+	 * @return array
596
+	 */
597
+	public function getTca(): array
598
+	{
599
+		return $this->tca;
600
+	}
601
+
602
+	/**
603
+	 * @return array
604
+	 */
605
+	public function getIncludedFields(): array
606
+	{
607
+		return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true);
608
+	}
609
+
610
+	/**
611
+	 * Return excluded fields from configuration + preferences.
612
+	 *
613
+	 * @return array
614
+	 */
615
+	public function getExcludedFields(): array
616
+	{
617
+		$configurationFields = $this->getExcludedFieldsFromConfiguration();
618
+		$preferencesFields = $this->getExcludedFieldsFromPreferences();
619
+
620
+		return array_merge($configurationFields, $preferencesFields);
621
+	}
622
+
623
+	/**
624
+	 * Fetch excluded fields from configuration.
625
+	 *
626
+	 * @return array
627
+	 */
628
+	protected function getExcludedFieldsFromConfiguration(): array
629
+	{
630
+		$excludedFields = [];
631
+		if (!empty($this->tca['excluded_fields'])) {
632
+			$excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true);
633
+		} elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason.
634
+			$excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true);
635
+		}
636
+		return $excludedFields;
637
+	}
638
+
639
+	/**
640
+	 * Fetch excluded fields from preferences.
641
+	 *
642
+	 * @return array
643
+	 */
644
+	protected function getExcludedFieldsFromPreferences(): array
645
+	{
646
+		$excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName);
647
+		return is_array($excludedFields) ? $excludedFields : [];
648
+	}
649
+
650
+	/**
651
+	 * @return bool
652
+	 */
653
+	public function areFilesIncludedInExport(): bool
654
+	{
655
+		$isIncluded = true;
656
+
657
+		if (isset($this->tca['export']['include_files'])) {
658
+			$isIncluded = (bool)$this->tca['export']['include_files'];
659
+		}
660
+		return $isIncluded;
661
+	}
662
+
663
+	/**
664
+	 * Returns a "facet" service instance.
665
+	 *
666
+	 * @param string|FacetInterface $facetName
667
+	 * @return StandardFacet
668
+	 */
669
+	protected function instantiateStandardFacet($facetName): StandardFacet
670
+	{
671
+		$label = $this->getLabel($facetName);
672
+
673
+		/** @var StandardFacet $facetName */
674
+		$facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label);
675
+
676
+		if (!$facet instanceof StandardFacet) {
677
+			throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345);
678
+		}
679
+		return $facet;
680
+	}
681
+
682
+	/**
683
+	 * Returns a "facet" service instance.
684
+	 *
685
+	 * @param string|FacetInterface $facetName
686
+	 * @return FacetInterface
687
+	 */
688
+	public function facet($facetName = ''): FacetInterface
689
+	{
690
+		$facets = $this->getFacets();
691
+		return $facets[$facetName];
692
+	}
693
+
694
+	/**
695
+	 * @return FieldPathResolver|object
696
+	 */
697
+	protected function getFieldPathResolver()
698
+	{
699
+		return GeneralUtility::makeInstance(FieldPathResolver::class);
700
+	}
701
+
702
+	/**
703
+	 * @return ModulePreferences|object
704
+	 */
705
+	protected function getModulePreferences()
706
+	{
707
+		return GeneralUtility::makeInstance(ModulePreferences::class);
708
+	}
709
+
710
+	/**
711
+	 * @return LanguageService|object
712
+	 */
713
+	protected function getLanguageService()
714
+	{
715
+		return GeneralUtility::makeInstance(LanguageService::class);
716
+	}
717 717
 }
Please login to merge, or discard this patch.
Classes/Command/VidiCommandController.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -22,57 +22,57 @@
 block discarded – undo
22 22
  */
23 23
 class VidiCommandController extends Command
24 24
 {
25
-    /**
26
-     * Configure the command by defining the name, options and arguments
27
-     */
28
-    protected function configure()
29
-    {
30
-        $this->setDescription('Check TCA configuration for relations used in grid.')
31
-        ->addOption(
32
-            'table',
33
-            'c',
34
-            InputOption::VALUE_NONE,
35
-            'The table name. If not defined check for every table.'
36
-        );
37
-    }
25
+	/**
26
+	 * Configure the command by defining the name, options and arguments
27
+	 */
28
+	protected function configure()
29
+	{
30
+		$this->setDescription('Check TCA configuration for relations used in grid.')
31
+		->addOption(
32
+			'table',
33
+			'c',
34
+			InputOption::VALUE_NONE,
35
+			'The table name. If not defined check for every table.'
36
+		);
37
+	}
38 38
 
39
-    /**
40
-     * Executes the command for removing the lock file
41
-     *
42
-     * @param InputInterface $input
43
-     * @param OutputInterface $output
44
-     */
45
-    protected function execute(InputInterface $input, OutputInterface $output)
46
-    {
47
-        $io = new SymfonyStyle($input, $output);
48
-        foreach ($GLOBALS['TCA'] as $tableName => $TCA) {
49
-            $table = $input->getOption('table');
50
-            if ($table !== '' && $table !== $tableName) {
51
-                continue;
52
-            }
39
+	/**
40
+	 * Executes the command for removing the lock file
41
+	 *
42
+	 * @param InputInterface $input
43
+	 * @param OutputInterface $output
44
+	 */
45
+	protected function execute(InputInterface $input, OutputInterface $output)
46
+	{
47
+		$io = new SymfonyStyle($input, $output);
48
+		foreach ($GLOBALS['TCA'] as $tableName => $TCA) {
49
+			$table = $input->getOption('table');
50
+			if ($table !== '' && $table !== $tableName) {
51
+				continue;
52
+			}
53 53
 
54
-            $fields = Tca::grid($tableName)->getFields();
55
-            if (!empty($fields)) {
56
-                $relations = $this->getGridAnalyserService()->checkRelationForTable($tableName);
57
-                if (!empty($relations)) {
58
-                    $io->text('');
59
-                    $io->text('--------------------------------------------------------------------');
60
-                    $io->text('');
61
-                    $io->text(sprintf('Relations for "%s"', $tableName));
62
-                    $io->text('');
63
-                    $io->text(implode("\n", $relations));
64
-                }
65
-            }
66
-        }
67
-    }
54
+			$fields = Tca::grid($tableName)->getFields();
55
+			if (!empty($fields)) {
56
+				$relations = $this->getGridAnalyserService()->checkRelationForTable($tableName);
57
+				if (!empty($relations)) {
58
+					$io->text('');
59
+					$io->text('--------------------------------------------------------------------');
60
+					$io->text('');
61
+					$io->text(sprintf('Relations for "%s"', $tableName));
62
+					$io->text('');
63
+					$io->text(implode("\n", $relations));
64
+				}
65
+			}
66
+		}
67
+	}
68 68
 
69
-    /**
70
-     * Get the Vidi Module Loader.
71
-     *
72
-     * @return GridAnalyserService|object
73
-     */
74
-    protected function getGridAnalyserService()
75
-    {
76
-        return GeneralUtility::makeInstance(GridAnalyserService::class);
77
-    }
69
+	/**
70
+	 * Get the Vidi Module Loader.
71
+	 *
72
+	 * @return GridAnalyserService|object
73
+	 */
74
+	protected function getGridAnalyserService()
75
+	{
76
+		return GeneralUtility::makeInstance(GridAnalyserService::class);
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Classes/View/AbstractComponentView.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -20,47 +20,47 @@
 block discarded – undo
20 20
  */
21 21
 abstract class AbstractComponentView implements ViewComponentInterface
22 22
 {
23
-    /**
24
-     * Get the Vidi Module Loader.
25
-     *
26
-     * @return ModuleLoader|object
27
-     */
28
-    protected function getModuleLoader()
29
-    {
30
-        return GeneralUtility::makeInstance(ModuleLoader::class);
31
-    }
23
+	/**
24
+	 * Get the Vidi Module Loader.
25
+	 *
26
+	 * @return ModuleLoader|object
27
+	 */
28
+	protected function getModuleLoader()
29
+	{
30
+		return GeneralUtility::makeInstance(ModuleLoader::class);
31
+	}
32 32
 
33
-    /**
34
-     * Returns an instance of the current Backend User.
35
-     *
36
-     * @return BackendUserAuthentication
37
-     */
38
-    protected function getBackendUser()
39
-    {
40
-        return $GLOBALS['BE_USER'];
41
-    }
33
+	/**
34
+	 * Returns an instance of the current Backend User.
35
+	 *
36
+	 * @return BackendUserAuthentication
37
+	 */
38
+	protected function getBackendUser()
39
+	{
40
+		return $GLOBALS['BE_USER'];
41
+	}
42 42
 
43
-    /**
44
-     * @return LanguageService|object
45
-     */
46
-    protected function getLanguageService()
47
-    {
48
-        return GeneralUtility::makeInstance(LanguageService::class);
49
-    }
43
+	/**
44
+	 * @return LanguageService|object
45
+	 */
46
+	protected function getLanguageService()
47
+	{
48
+		return GeneralUtility::makeInstance(LanguageService::class);
49
+	}
50 50
 
51
-    /**
52
-     * @return IconFactory|object
53
-     */
54
-    protected function getIconFactory()
55
-    {
56
-        return GeneralUtility::makeInstance(IconFactory::class);
57
-    }
51
+	/**
52
+	 * @return IconFactory|object
53
+	 */
54
+	protected function getIconFactory()
55
+	{
56
+		return GeneralUtility::makeInstance(IconFactory::class);
57
+	}
58 58
 
59
-    /**
60
-     * @return LinkButton|object
61
-     */
62
-    protected function makeLinkButton()
63
-    {
64
-        return GeneralUtility::makeInstance(LinkButton::class);
65
-    }
59
+	/**
60
+	 * @return LinkButton|object
61
+	 */
62
+	protected function makeLinkButton()
63
+	{
64
+		return GeneralUtility::makeInstance(LinkButton::class);
65
+	}
66 66
 }
Please login to merge, or discard this patch.