[BUGFIX] Fix foreign_table_where GROUP BY handling
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / InlineOverrideChildTca.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
19
20 /**
21 * Override child TCA in an inline parent child relation.
22 *
23 * This basically merges the inline property ['overrideChildTca'] from
24 * parent TCA over given child TCA.
25 */
26 class InlineOverrideChildTca implements FormDataProviderInterface
27 {
28 /**
29 * ['columns'] section child TCA field names that can not be overridden
30 * by overrideChildTca from parent.
31 *
32 * @var array
33 */
34 protected $notSettableFields = [
35 'uid',
36 'pid',
37 't3ver_oid',
38 't3ver_id',
39 't3ver_label',
40 't3ver_wsid',
41 't3ver_state',
42 't3ver_stage',
43 't3ver_count',
44 't3ver_tstamp',
45 't3ver_move_id',
46 ];
47
48 /**
49 * Configuration fields in ctrl section. Their values are field names and if the
50 * keys are set in ['ctrl'] section, they are added to the $notSettableFields list
51 * and can not be overridden, too.
52 *
53 * @var array
54 */
55 protected $configurationKeysForNotSettableFields = [
56 'crdate',
57 'cruser_id',
58 'delete',
59 'origUid',
60 'transOrigDiffSourceField',
61 'transOrigPointerField',
62 'tstamp',
63 ];
64
65 /**
66 * Inline parent TCA may override some TCA of children.
67 *
68 * @param array $result Main result array
69 * @return array Modified result array
70 */
71 public function addData(array $result): array
72 {
73 $result = $this->overrideTypes($result);
74 return $this->overrideColumns($result);
75 }
76
77 /**
78 * Override ['types'] configuration in child TCA
79 *
80 * @param array $result Main result array
81 * @return array Modified result array
82 */
83 protected function overrideTypes(array $result): array
84 {
85 if (!isset($result['inlineParentConfig']['overrideChildTca']['types'])) {
86 return $result;
87 }
88 $result['processedTca']['types'] = array_replace_recursive(
89 $result['processedTca']['types'],
90 $result['inlineParentConfig']['overrideChildTca']['types']
91 );
92 return $result;
93 }
94
95 /**
96 * Override ['columns'] configuration in child TCA.
97 * Sanitizes that various hard dependencies can not be changed.
98 *
99 * @param array $result Main result array
100 * @return array Modified result array
101 * @throws \RuntimeException
102 */
103 protected function overrideColumns(array $result): array
104 {
105 if (!isset($result['inlineParentConfig']['overrideChildTca']['columns'])) {
106 return $result;
107 }
108 $fieldBlackList = $this->generateFieldBlackList($result);
109 foreach ($fieldBlackList as $notChangeableFieldName) {
110 if (isset($result['inlineParentConfig']['overrideChildTca']['columns'][$notChangeableFieldName])) {
111 throw new \RuntimeException(
112 'System field \'' . $notChangeableFieldName . '\' can not be overridden in inline config'
113 . ' \'overrideChildTca\' from parent TCA',
114 1490371322
115 );
116 }
117 }
118 $result['processedTca']['columns'] = array_replace_recursive(
119 $result['processedTca']['columns'],
120 $result['inlineParentConfig']['overrideChildTca']['columns']
121 );
122 return $result;
123 }
124
125 /**
126 * Add field names defined in ctrl section of child table to black list
127 *
128 * @param array $result Main result array
129 * @return array Column field names which can not be changed by parent TCA
130 */
131 protected function generateFieldBlackList(array $result): array
132 {
133 $notSettableFields = $this->notSettableFields;
134 foreach ($this->configurationKeysForNotSettableFields as $configurationKey) {
135 if (isset($result['processedTca']['ctrl'][$configurationKey])) {
136 $notSettableFields[] = $result['processedTca']['ctrl'][$configurationKey];
137 }
138 }
139 return $notSettableFields;
140 }
141 }