TYPO3 CMS  TYPO3_7-6
TcaCheckboxItems.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  $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'] !== 'check') {
39  continue;
40  }
41 
42  if (!is_array($fieldConfig['config']['items'])) {
43  $fieldConfig['config']['items'] = [];
44  }
45 
46  $config = $fieldConfig['config'];
47  $items = $config['items'];
48 
49  // Sanitize items
50  $newItems = [];
51  foreach ($items as $itemKey => $itemValue) {
52  if (!is_array($itemValue)) {
53  throw new \UnexpectedValueException(
54  'Item ' . $itemKey . ' of field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' is no array as exepcted',
55  1440499337
56  );
57  }
58  if (!array_key_exists(0, $itemValue)) {
59  throw new \UnexpectedValueException(
60  'Item ' . $itemKey . ' of field ' . $fieldName . ' of TCA table ' . $result['tableName'] . ' has no label',
61  1440499338
62  );
63  }
64  if (!array_key_exists(1, $itemValue)) {
65  $itemValue[1] = '';
66  }
67  $newItems[$itemKey] = [
68  $languageService->sL(trim($itemValue[0])),
69  $itemValue[1]
70  ];
71  }
72  $items = $newItems;
73 
74  // Resolve "itemsProcFunc"
75  if (!empty($config['itemsProcFunc'])) {
76  $items = $this->resolveItemProcessorFunction($result, $fieldName, $items);
77  // itemsProcFunc must not be used anymore
78  unset($result['processedTca']['columns'][$fieldName]['config']['itemsProcFunc']);
79  }
80 
81  // Set label overrides from pageTsConfig if given
82  if (isset($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'])
83  && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'])
84  ) {
85  foreach ($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['altLabels.'] as $itemKey => $label) {
86  if (isset($items[$itemKey][0])) {
87  $items[$itemKey][0] = $languageService->sL($label);
88  }
89  }
90  }
91 
92  $result['processedTca']['columns'][$fieldName]['config']['items'] = $items;
93  }
94 
95  return $result;
96  }
97 
101  protected function getLanguageService()
102  {
103  return $GLOBALS['LANG'];
104  }
105 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']