TYPO3 CMS  TYPO3_8-7
TcaColumnsProcessFieldLabels.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 
20 
27 {
34  public function addData(array $result)
35  {
36  $result = $this->setLabelFromShowitemAndPalettes($result);
37  $result = $this->setLabelFromPageTsConfig($result);
38  $result = $this->translateLabels($result);
39  return $result;
40  }
41 
53  protected function setLabelFromShowitemAndPalettes(array $result)
54  {
55  $recordTypeValue = $result['recordTypeValue'];
56  // flex forms don't have a showitem / palettes configuration - early return
57  if (!isset($result['processedTca']['types'][$recordTypeValue]['showitem'])) {
58  return $result;
59  }
60  $showItemArray = GeneralUtility::trimExplode(',', $result['processedTca']['types'][$recordTypeValue]['showitem']);
61  foreach ($showItemArray as $aShowItemFieldString) {
62  $aShowItemFieldArray = GeneralUtility::trimExplode(';', $aShowItemFieldString);
63  $aShowItemFieldArray = [
64  'fieldName' => $aShowItemFieldArray[0],
65  'fieldLabel' => $aShowItemFieldArray[1] ?: null,
66  'paletteName' => $aShowItemFieldArray[2] ?: null,
67  ];
68  if ($aShowItemFieldArray['fieldName'] === '--div--') {
69  // tabs are not of interest here
70  continue;
71  }
72  if ($aShowItemFieldArray['fieldName'] === '--palette--') {
73  // showitem references to a palette field. unpack the palette and process
74  // label overrides that may be in there.
75  if (!isset($result['processedTca']['palettes'][$aShowItemFieldArray['paletteName']]['showitem'])) {
76  // No palette with this name found? Skip it.
77  continue;
78  }
79  $palettesArray = GeneralUtility::trimExplode(
80  ',',
81  $result['processedTca']['palettes'][$aShowItemFieldArray['paletteName']]['showitem']
82  );
83  foreach ($palettesArray as $aPalettesString) {
84  $aPalettesArray = GeneralUtility::trimExplode(';', $aPalettesString);
85  $aPalettesArray = [
86  'fieldName' => $aPalettesArray[0],
87  'fieldLabel' => $aPalettesArray[1] ?: null,
88  ];
89  if (!empty($aPalettesArray['fieldLabel'])
90  && isset($result['processedTca']['columns'][$aPalettesArray['fieldName']])
91  ) {
92  $result['processedTca']['columns'][$aPalettesArray['fieldName']]['label'] = $aPalettesArray['fieldLabel'];
93  }
94  }
95  } else {
96  // If the field has a label in the showitem configuration of this record type, use it.
97  // showitem = 'aField, aFieldWithLabelOverride;theLabel, anotherField'
98  if (!empty($aShowItemFieldArray['fieldLabel'])
99  && isset($result['processedTca']['columns'][$aShowItemFieldArray['fieldName']])
100  ) {
101  $result['processedTca']['columns'][$aShowItemFieldArray['fieldName']]['label'] = $aShowItemFieldArray['fieldLabel'];
102  }
103  }
104  }
105  return $result;
106  }
107 
117  protected function setLabelFromPageTsConfig(array $result)
118  {
119  $languageService = $this->getLanguageService();
120  $table = $result['tableName'];
121  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfiguration) {
122  $fieldTSConfig = [];
123  if (isset($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'])
124  && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'])
125  ) {
126  $fieldTSConfig = $result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'];
127  }
128  if (!empty($fieldTSConfig['label'])) {
129  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label'];
130  }
131  if (!empty($fieldTSConfig['label.'][$languageService->lang])) {
132  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label.'][$languageService->lang];
133  }
134  }
135  return $result;
136  }
137 
144  protected function translateLabels(array $result)
145  {
146  $languageService = $this->getLanguageService();
147  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfiguration) {
148  if (!isset($fieldConfiguration['label'])) {
149  continue;
150  }
151  $result['processedTca']['columns'][$fieldName]['label'] = $languageService->sL($fieldConfiguration['label']);
152  }
153  return $result;
154  }
155 
159  protected function getLanguageService()
160  {
161  return $GLOBALS['LANG'];
162  }
163 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']