‪TYPO3CMS  10.4
TcaRadioItems.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  $languageService = $this->‪getLanguageService();
36  $table = $result['tableName'];
37 
38  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
39  if (empty($fieldConfig['config']['type']) || $fieldConfig['config']['type'] !== 'radio') {
40  continue;
41  }
42 
43  if (!isset($fieldConfig['config']['items']) || !is_array($fieldConfig['config']['items'])) {
44  throw new \UnexpectedValueException(
45  'Radio field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' must have \'config\' \'items\' definition',
46  1438594829
47  );
48  }
49 
50  $config = $fieldConfig['config'];
51  $items = $config['items'];
52 
53  // Sanitize items and translate labels
54  $newItems = [];
55  foreach ($items as $itemKey => $itemValue) {
56  if (!is_array($itemValue)) {
57  throw new \UnexpectedValueException(
58  'Item ' . $itemKey . ' of field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' is not an array as expected',
59  1438607163
60  );
61  }
62  if (!array_key_exists(0, $itemValue)) {
63  throw new \UnexpectedValueException(
64  'Item ' . $itemKey . ' of field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' has no label',
65  1438607164
66  );
67  }
68  if (!array_key_exists(1, $itemValue)) {
69  throw new \UnexpectedValueException(
70  'Item ' . $itemKey . ' of field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' has no value',
71  1438607165
72  );
73  }
74  $newItems[$itemKey] = [
75  $languageService->sL(trim($itemValue[0])),
76  $itemValue[1]
77  ];
78  }
79  $items = $newItems;
80 
81  // Resolve "itemsProcFunc"
82  if (!empty($config['itemsProcFunc'])) {
83  $items = $this->‪resolveItemProcessorFunction($result, $fieldName, $items);
84  // itemsProcFunc must not be used anymore
85  unset($result['processedTca']['columns'][$fieldName]['config']['itemsProcFunc']);
86  }
87 
88  // Set label overrides from pageTsConfig if given
89  if (isset($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'])
90  && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'])
91  ) {
92  foreach ($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'] as $itemKey => $label) {
93  if (isset($items[$itemKey][0])) {
94  $items[$itemKey][0] = $languageService->sL(trim($label));
95  }
96  }
97  }
98 
99  $result['processedTca']['columns'][$fieldName]['config']['items'] = $items;
100  }
101 
102  return $result;
103  }
104 
108  protected function ‪getLanguageService()
109  {
110  return ‪$GLOBALS['LANG'];
111  }
112 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems\getLanguageService
‪LanguageService getLanguageService()
Definition: TcaRadioItems.php:108
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\resolveItemProcessorFunction
‪array resolveItemProcessorFunction(array $result, $fieldName, array $items)
Definition: AbstractItemProvider.php:59
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider
Definition: AbstractItemProvider.php:50
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems\addData
‪array addData(array $result)
Definition: TcaRadioItems.php:33
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems
Definition: TcaRadioItems.php:25