[TASK] Fix CGL errors
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / InlineOverrideChildTca.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
18 use TYPO3\CMS\Core\Utility\ArrayUtility;
19
20 /**
21 * Override some child TCA in an inline parent child relation.
22 */
23 class InlineOverrideChildTca implements FormDataProviderInterface
24 {
25 /**
26 * Inline parent TCA may override some TCA of children.
27 *
28 * @param array $result
29 * @return array
30 */
31 public function addData(array $result)
32 {
33 // Replace types definition of inline child if foreign_types is defined in inlineParentConfig
34 if (isset($result['inlineParentConfig']['foreign_types'])) {
35 foreach ($result['inlineParentConfig']['foreign_types'] as $type => $config) {
36 $result['processedTca']['types'][$type] = $config;
37 }
38 }
39
40 // Override config section of foreign_selector field pointer if given
41 if (isset($result['inlineParentConfig']['foreign_selector'])
42 && is_string($result['inlineParentConfig']['foreign_selector'])
43 && isset($result['inlineParentConfig']['foreign_selector_fieldTcaOverride'])
44 && is_array($result['inlineParentConfig']['foreign_selector_fieldTcaOverride'])
45 && isset($result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']])
46 && is_array($result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']])
47 ) {
48 ArrayUtility::mergeRecursiveWithOverrule(
49 $result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']],
50 $result['inlineParentConfig']['foreign_selector_fieldTcaOverride']
51 );
52 }
53
54 // Set default values for (new) child if foreign_record_defaults is defined in inlineParentConfig
55 if (isset($result['inlineParentConfig']['foreign_record_defaults']) && is_array($result['inlineParentConfig']['foreign_record_defaults'])) {
56 $foreignTableConfig = $GLOBALS['TCA'][$result['inlineParentConfig']['foreign_table']];
57 // The following system relevant fields can't be set by foreign_record_defaults
58 $notSetableFields = [
59 'uid',
60 'pid',
61 't3ver_oid',
62 't3ver_id',
63 't3ver_label',
64 't3ver_wsid',
65 't3ver_state',
66 't3ver_stage',
67 't3ver_count',
68 't3ver_tstamp',
69 't3ver_move_id',
70 ];
71 // Optional configuration fields used in child table. If set, they must not be overridden, either
72 $configurationKeysForNotSettableFields = [
73 'crdate',
74 'cruser_id',
75 'delete',
76 'origUid',
77 'transOrigDiffSourceField',
78 'transOrigPointerField',
79 'tstamp',
80 ];
81 foreach ($configurationKeysForNotSettableFields as $configurationKey) {
82 if (isset($foreignTableConfig['ctrl'][$configurationKey])) {
83 $notSetableFields[] = $foreignTableConfig['ctrl'][$configurationKey];
84 }
85 }
86 foreach ($result['inlineParentConfig']['foreign_record_defaults'] as $fieldName => $defaultValue) {
87 if (isset($foreignTableConfig['columns'][$fieldName]) && !in_array($fieldName, $notSetableFields, true)) {
88 $result['processedTca']['columns'][$fieldName]['config']['default'] = $defaultValue;
89 }
90 }
91 }
92 return $result;
93 }
94 }