‪TYPO3CMS  11.5
TcaInlineConfiguration.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
33  public function ‪addData(array $result)
34  {
35  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
36  if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'inline') {
37  continue;
38  }
39 
40  // Throw if an inline field without foreign_table is set
41  if (!isset($fieldConfig['config']['foreign_table'])) {
42  throw new \UnexpectedValueException(
43  'Inline field ' . $fieldName . ' of table ' . $result['tableName'] . ' must have a foreign_table config',
44  1443793404
45  );
46  }
47 
48  $result = $this->‪initializeMinMaxItems($result, $fieldName);
49  $result = $this->‪initializeChildrenLanguage($result, $fieldName);
50  $result = $this->‪initializeAppearance($result, $fieldName);
51  $result = $this->‪addInlineSelectorAndUniqueConfiguration($result, $fieldName);
52  }
53 
54  // If field is set to readOnly, set all fields of the relation to readOnly as well
55  if (isset($result['inlineParentConfig']) && isset($result['inlineParentConfig']['readOnly']) && $result['inlineParentConfig']['readOnly']) {
56  foreach ($result['processedTca']['columns'] as $columnName => $columnConfiguration) {
57  $result['processedTca']['columns'][$columnName]['config']['readOnly'] = true;
58  }
59  }
60 
61  return $result;
62  }
63 
72  protected function ‪initializeMinMaxItems(array $result, $fieldName)
73  {
74  $config = $result['processedTca']['columns'][$fieldName]['config'];
75 
76  $minItems = 0;
77  if (isset($config['minitems'])) {
78  $minItems = ‪MathUtility::forceIntegerInRange($config['minitems'], 0);
79  }
80  $result['processedTca']['columns'][$fieldName]['config']['minitems'] = $minItems;
81 
82  $maxItems = 99999;
83  if (isset($config['maxitems'])) {
84  $maxItems = ‪MathUtility::forceIntegerInRange($config['maxitems'], 1);
85  }
86  $result['processedTca']['columns'][$fieldName]['config']['maxitems'] = $maxItems;
87 
88  return $result;
89  }
90 
99  protected function ‪initializeAppearance(array $result, $fieldName)
100  {
101  $config = $result['processedTca']['columns'][$fieldName]['config'];
102  if (!isset($config['appearance']) || !is_array($config['appearance'])) {
103  // Init appearance if not set
104  $config['appearance'] = [];
105  }
106  // Initialize position of the level links
107  if (!isset($config['appearance']['levelLinksPosition'])
108  || !in_array($config['appearance']['levelLinksPosition'], ['top', 'bottom', 'both'], true)
109  ) {
110  $config['appearance']['levelLinksPosition'] = 'top';
111  }
112  // Hide level links (no matter the defined position) for "use combination"
113  if (isset($config['foreign_selector']) && $config['foreign_selector']
114  && (!isset($config['appearance']['useCombination']) || !$config['appearance']['useCombination'])
115  ) {
116  $config['appearance']['showAllLocalizationLink'] = false;
117  $config['appearance']['showSynchronizationLink'] = false;
118  $config['appearance']['showNewRecordLink'] = false;
119  }
120  $config['appearance']['showPossibleLocalizationRecords']
121  = isset($config['appearance']['showPossibleLocalizationRecords']) && $config['appearance']['showPossibleLocalizationRecords'];
122  // Defines which controls should be shown in header of each record
123  $enabledControls = [
124  'info' => true,
125  'new' => true,
126  'dragdrop' => true,
127  'sort' => true,
128  'hide' => true,
129  'delete' => true,
130  'localize' => true,
131  ];
132  if (isset($config['appearance']['enabledControls']) && is_array($config['appearance']['enabledControls'])) {
133  $config['appearance']['enabledControls'] = array_merge($enabledControls, $config['appearance']['enabledControls']);
134  } else {
135  $config['appearance']['enabledControls'] = $enabledControls;
136  }
137  $result['processedTca']['columns'][$fieldName]['config'] = $config;
138 
139  return $result;
140  }
141 
155  protected function ‪initializeChildrenLanguage(array $result, $fieldName)
156  {
157  $childTableName = $result['processedTca']['columns'][$fieldName]['config']['foreign_table'];
158 
159  if (empty($result['processedTca']['ctrl']['languageField'])
160  || empty(‪$GLOBALS['TCA'][$childTableName]['ctrl']['languageField'])
161  ) {
162  return $result;
163  }
164 
165  $parentConfig = $result['processedTca']['columns'][$fieldName]['config'];
166 
167  $parentLanguageField = $result['processedTca']['ctrl']['languageField'];
168  if (!isset($parentConfig['inline']['parentSysLanguageUid'])
169  && isset($result['databaseRow'][$parentLanguageField])
170  ) {
171  if (is_array($result['databaseRow'][$parentLanguageField])) {
172  $result['processedTca']['columns'][$fieldName]['config']['inline']['parentSysLanguageUid']
173  = (int)($result['databaseRow'][$parentLanguageField][0] ?? 0);
174  } else {
175  $result['processedTca']['columns'][$fieldName]['config']['inline']['parentSysLanguageUid']
176  = (int)($result['databaseRow'][$parentLanguageField] ?? 0);
177  }
178  }
179 
180  return $result;
181  }
182 
197  protected function ‪addInlineSelectorAndUniqueConfiguration(array $result, $fieldName)
198  {
199  $config = $result['processedTca']['columns'][$fieldName]['config'];
200 
201  // Early return if neither foreign_unique nor foreign_selector are set
202  if (!isset($config['foreign_unique']) && !isset($config['foreign_selector'])) {
203  return $result;
204  }
205 
206  // If both are set, they must point to the same field
207  if (isset($config['foreign_unique']) && isset($config['foreign_selector'])
208  && $config['foreign_unique'] !== $config['foreign_selector']
209  ) {
210  throw new \UnexpectedValueException(
211  'Table ' . $result['tableName'] . ' field ' . $fieldName . ': If both foreign_unique and'
212  . ' foreign_selector are set, they must point to the same field',
213  1444995464
214  );
215  }
216 
217  if (isset($config['foreign_unique'])) {
218  $fieldNameInChildConfiguration = $config['foreign_unique'];
219  } else {
220  $fieldNameInChildConfiguration = $config['foreign_selector'];
221  }
222 
223  // Throw if field name in globals does not exist or is not of type select or group
224  if (!isset(‪$GLOBALS['TCA'][$config['foreign_table']]['columns'][$fieldNameInChildConfiguration]['config']['type'])
225  || (‪$GLOBALS['TCA'][$config['foreign_table']]['columns'][$fieldNameInChildConfiguration]['config']['type'] !== 'select'
226  && ‪$GLOBALS['TCA'][$config['foreign_table']]['columns'][$fieldNameInChildConfiguration]['config']['type'] !== 'group')
227  ) {
228  throw new \UnexpectedValueException(
229  'Table ' . $result['tableName'] . ' field ' . $fieldName . ' points in foreign_selector or foreign_unique'
230  . ' to field ' . $fieldNameInChildConfiguration . ' of table ' . $config['foreign_table'] . ', but this field'
231  . ' is either not defined or is not of type select or group',
232  1444996537
233  );
234  }
235 
236  $selectorOrUniqueConfiguration = [
237  'config' => ‪$GLOBALS['TCA'][$config['foreign_table']]['columns'][$fieldNameInChildConfiguration]['config'],
238  ];
239 
240  // Throw exception if field is of type "group", but "internal_type" is either not set nor "internal_type" is set to "db"
241  if ($selectorOrUniqueConfiguration['config']['type'] === 'group'
242  && isset($selectorOrUniqueConfiguration['config']['internal_type'])
243  && $selectorOrUniqueConfiguration['config']['internal_type'] !== 'db'
244  ) {
245  throw new \UnexpectedValueException(
246  'Table ' . $result['tableName'] . ' field ' . $fieldName . ' points in foreign_selector or foreign_unique'
247  . ' to field ' . $fieldNameInChildConfiguration . ' of table ' . $config['foreign_table'] . '. This field'
248  . ' is of type group and must have no internal_type set, or set to \'db\'',
249  1444999130
250  );
251  }
252 
253  // Merge overrideChildTca of foreign_selector if given
254  if (isset($config['foreign_selector'], $config['overrideChildTca']['columns'][$config['foreign_selector']]['config'])
255  && is_array($config['overrideChildTca']['columns'][$config['foreign_selector']]['config'])
256  ) {
257  $selectorOrUniqueConfiguration['config'] = array_replace_recursive($selectorOrUniqueConfiguration['config'], $config['overrideChildTca']['columns'][$config['foreign_selector']]['config']);
258  }
259 
260  // Add field name to config for easy access later
261  $selectorOrUniqueConfiguration['fieldName'] = $fieldNameInChildConfiguration;
262 
263  // Add remote table name for easy access later
264  if ($selectorOrUniqueConfiguration['config']['type'] === 'select') {
265  if (!isset($selectorOrUniqueConfiguration['config']['foreign_table'])) {
266  throw new \UnexpectedValueException(
267  'Table ' . $result['tableName'] . ' field ' . $fieldName . ' points in foreign_selector or foreign_unique'
268  . ' to field ' . $fieldNameInChildConfiguration . ' of table ' . $config['foreign_table'] . '. This field'
269  . ' is of type select and must define foreign_table',
270  1445078627
271  );
272  }
273  $foreignTable = $selectorOrUniqueConfiguration['config']['foreign_table'];
274  } else {
275  if (!isset($selectorOrUniqueConfiguration['config']['allowed'])) {
276  throw new \UnexpectedValueException(
277  'Table ' . $result['tableName'] . ' field ' . $fieldName . ' points in foreign_selector or foreign_unique'
278  . ' to field ' . $fieldNameInChildConfiguration . ' of table ' . $config['foreign_table'] . '. This field'
279  . ' is of type select and must define allowed',
280  1445078628
281  );
282  }
283  $foreignTable = $selectorOrUniqueConfiguration['config']['allowed'];
284  }
285  $selectorOrUniqueConfiguration['foreignTable'] = $foreignTable;
286 
287  // If this is a foreign_selector field, mark it as such for data fetching later
288  $selectorOrUniqueConfiguration['isSelector'] = false;
289  if (isset($config['foreign_selector'])) {
290  $selectorOrUniqueConfiguration['isSelector'] = true;
291  }
292 
293  // If this is a foreign_unique field, mark it a such for unique data fetching later
294  $selectorOrUniqueConfiguration['isUnique'] = false;
295  if (isset($config['foreign_unique'])) {
296  $selectorOrUniqueConfiguration['isUnique'] = true;
297  }
298 
299  // Add field configuration to inline configuration
300  $result['processedTca']['columns'][$fieldName]['config']['selectorOrUniqueConfiguration'] = $selectorOrUniqueConfiguration;
301 
302  return $result;
303  }
304 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration\initializeChildrenLanguage
‪array initializeChildrenLanguage(array $result, $fieldName)
Definition: TcaInlineConfiguration.php:155
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration\addData
‪array addData(array $result)
Definition: TcaInlineConfiguration.php:33
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration
Definition: TcaInlineConfiguration.php:25
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration\addInlineSelectorAndUniqueConfiguration
‪array addInlineSelectorAndUniqueConfiguration(array $result, $fieldName)
Definition: TcaInlineConfiguration.php:197
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration\initializeAppearance
‪array initializeAppearance(array $result, $fieldName)
Definition: TcaInlineConfiguration.php:99
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInlineConfiguration\initializeMinMaxItems
‪array initializeMinMaxItems(array $result, $fieldName)
Definition: TcaInlineConfiguration.php:72
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22