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