TYPO3  7.6
InlineOverrideChildTca.php
Go to the documentation of this file.
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 
19 
24 {
25 
32  public function addData(array $result)
33  {
34  // Replace types definition of inline child if foreign_types is defined in inlineParentConfig
35  if (isset($result['inlineParentConfig']['foreign_types'])) {
36  foreach ($result['inlineParentConfig']['foreign_types'] as $type => $config) {
37  $result['processedTca']['types'][$type] = $config;
38  }
39  }
40 
41  // Override config section of foreign_selector field pointer if given
42  if (isset($result['inlineParentConfig']['foreign_selector'])
43  && is_string($result['inlineParentConfig']['foreign_selector'])
44  && isset($result['inlineParentConfig']['foreign_selector_fieldTcaOverride'])
45  && is_array($result['inlineParentConfig']['foreign_selector_fieldTcaOverride'])
46  && isset($result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']])
47  && is_array($result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']])
48  ) {
50  $result['processedTca']['columns'][$result['inlineParentConfig']['foreign_selector']],
51  $result['inlineParentConfig']['foreign_selector_fieldTcaOverride']
52  );
53  }
54 
55  // Set default values for (new) child if foreign_record_defaults is defined in inlineParentConfig
56  if (isset($result['inlineParentConfig']['foreign_record_defaults']) && is_array($result['inlineParentConfig']['foreign_record_defaults'])) {
57  $foreignTableConfig = $GLOBALS['TCA'][$result['inlineParentConfig']['foreign_table']];
58  // The following system relevant fields can't be set by foreign_record_defaults
59  $notSetableFields = [
60  'uid',
61  'pid',
62  't3ver_oid',
63  't3ver_id',
64  't3ver_label',
65  't3ver_wsid',
66  't3ver_state',
67  't3ver_stage',
68  't3ver_count',
69  't3ver_tstamp',
70  't3ver_move_id',
71  ];
72  // Optional configuration fields used in child table. If set, they must not be overridden, either
73  $configurationKeysForNotSettableFields = [
74  'crdate',
75  'cruser_id',
76  'delete',
77  'origUid',
78  'transOrigDiffSourceField',
79  'transOrigPointerField',
80  'tstamp',
81  ];
82  foreach ($configurationKeysForNotSettableFields as $configurationKey) {
83  if (isset($foreignTableConfig['ctrl'][$configurationKey])) {
84  $notSetableFields[] = $foreignTableConfig['ctrl'][$configurationKey];
85  }
86  }
87  foreach ($result['inlineParentConfig']['foreign_record_defaults'] as $fieldName => $defaultValue) {
88  if (isset($foreignTableConfig['columns'][$fieldName]) && !in_array($fieldName, $notSetableFields, true)) {
89  $result['processedTca']['columns'][$fieldName]['config']['default'] = $defaultValue;
90  }
91  }
92  }
93  return $result;
94  }
95 }