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