[!!!][TASK] Remove t3ver_label database field
[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_wsid',
40 't3ver_state',
41 't3ver_stage',
42 't3ver_count',
43 't3ver_tstamp',
44 't3ver_move_id',
45 ];
46
47 /**
48 * Configuration fields in ctrl section. Their values are field names and if the
49 * keys are set in ['ctrl'] section, they are added to the $notSettableFields list
50 * and can not be overridden, too.
51 *
52 * @var array
53 */
54 protected $configurationKeysForNotSettableFields = [
55 'crdate',
56 'cruser_id',
57 'delete',
58 'origUid',
59 'transOrigDiffSourceField',
60 'transOrigPointerField',
61 'tstamp',
62 ];
63
64 /**
65 * Inline parent TCA may override some TCA of children.
66 *
67 * @param array $result Main result array
68 * @return array Modified result array
69 */
70 public function addData(array $result): array
71 {
72 $result = $this->overrideTypes($result);
73 return $this->overrideColumns($result);
74 }
75
76 /**
77 * Override ['types'] configuration in child TCA
78 *
79 * @param array $result Main result array
80 * @return array Modified result array
81 */
82 protected function overrideTypes(array $result): array
83 {
84 if (!isset($result['inlineParentConfig']['overrideChildTca']['types'])) {
85 return $result;
86 }
87 $result['processedTca']['types'] = array_replace_recursive(
88 $result['processedTca']['types'],
89 $result['inlineParentConfig']['overrideChildTca']['types']
90 );
91 return $result;
92 }
93
94 /**
95 * Override ['columns'] configuration in child TCA.
96 * Sanitizes that various hard dependencies can not be changed.
97 *
98 * @param array $result Main result array
99 * @return array Modified result array
100 * @throws \RuntimeException
101 */
102 protected function overrideColumns(array $result): array
103 {
104 if (!isset($result['inlineParentConfig']['overrideChildTca']['columns'])) {
105 return $result;
106 }
107 $fieldBlackList = $this->generateFieldBlackList($result);
108 foreach ($fieldBlackList as $notChangeableFieldName) {
109 if (isset($result['inlineParentConfig']['overrideChildTca']['columns'][$notChangeableFieldName])) {
110 throw new \RuntimeException(
111 'System field \'' . $notChangeableFieldName . '\' can not be overridden in inline config'
112 . ' \'overrideChildTca\' from parent TCA',
113 1490371322
114 );
115 }
116 }
117 $result['processedTca']['columns'] = array_replace_recursive(
118 $result['processedTca']['columns'],
119 $result['inlineParentConfig']['overrideChildTca']['columns']
120 );
121 return $result;
122 }
123
124 /**
125 * Add field names defined in ctrl section of child table to black list
126 *
127 * @param array $result Main result array
128 * @return array Column field names which can not be changed by parent TCA
129 */
130 protected function generateFieldBlackList(array $result): array
131 {
132 $notSettableFields = $this->notSettableFields;
133 foreach ($this->configurationKeysForNotSettableFields as $configurationKey) {
134 if (isset($result['processedTca']['ctrl'][$configurationKey])) {
135 $notSettableFields[] = $result['processedTca']['ctrl'][$configurationKey];
136 }
137 }
138 return $notSettableFields;
139 }
140 }