029f4f5973faf6f1a64f0a550fb61f1137b27aa3
[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
19 /**
20 * Override some child TCA in an inline parent child relation.
21 */
22 class InlineOverrideChildTca implements FormDataProviderInterface
23 {
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 // Set default values for (new) child if foreign_record_defaults is defined in inlineParentConfig
41 if (isset($result['inlineParentConfig']['foreign_record_defaults']) && is_array($result['inlineParentConfig']['foreign_record_defaults'])) {
42 $foreignTableConfig = $GLOBALS['TCA'][$result['inlineParentConfig']['foreign_table']];
43 // The following system relevant fields can't be set by foreign_record_defaults
44 $notSetableFields = [
45 'uid',
46 'pid',
47 't3ver_oid',
48 't3ver_id',
49 't3ver_label',
50 't3ver_wsid',
51 't3ver_state',
52 't3ver_stage',
53 't3ver_count',
54 't3ver_tstamp',
55 't3ver_move_id',
56 ];
57 // Optional configuration fields used in child table. If set, they must not be overridden, either
58 $configurationKeysForNotSettableFields = [
59 'crdate',
60 'cruser_id',
61 'delete',
62 'origUid',
63 'transOrigDiffSourceField',
64 'transOrigPointerField',
65 'tstamp',
66 ];
67 foreach ($configurationKeysForNotSettableFields as $configurationKey) {
68 if (isset($foreignTableConfig['ctrl'][$configurationKey])) {
69 $notSetableFields[] = $foreignTableConfig['ctrl'][$configurationKey];
70 }
71 }
72 foreach ($result['inlineParentConfig']['foreign_record_defaults'] as $fieldName => $defaultValue) {
73 if (isset($foreignTableConfig['columns'][$fieldName]) && !in_array($fieldName, $notSetableFields, TRUE)) {
74 $result['processedTca']['columns'][$fieldName]['config']['default'] = $defaultValue;
75 }
76 }
77 }
78 return $result;
79 }
80 }