TYPO3 CMS  TYPO3_7-6
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  } elseif ($aShowItemFieldArray['fieldName'] === '--palette--') {
72  // showitem references to a palette field. unpack the palette and process
73  // label overrides that may be in there.
74  if (!isset($result['processedTca']['palettes'][$aShowItemFieldArray['paletteName']]['showitem'])) {
75  // No palette with this name found? Skip it.
76  continue;
77  }
78  $palettesArray = GeneralUtility::trimExplode(
79  ',',
80  $result['processedTca']['palettes'][$aShowItemFieldArray['paletteName']]['showitem']
81  );
82  foreach ($palettesArray as $aPalettesString) {
83  $aPalettesArray = GeneralUtility::trimExplode(';', $aPalettesString);
84  $aPalettesArray = [
85  'fieldName' => $aPalettesArray[0],
86  'fieldLabel' => $aPalettesArray[1] ?: null,
87  ];
88  if (!empty($aPalettesArray['fieldLabel'])
89  && isset($result['processedTca']['columns'][$aPalettesArray['fieldName']])
90  ) {
91  $result['processedTca']['columns'][$aPalettesArray['fieldName']]['label'] = $aPalettesArray['fieldLabel'];
92  }
93  }
94  } else {
95  // If the field has a label in the showitem configuration of this record type, use it.
96  // showitem = 'aField, aFieldWithLabelOverride;theLabel, anotherField'
97  if (!empty($aShowItemFieldArray['fieldLabel'])
98  && isset($result['processedTca']['columns'][$aShowItemFieldArray['fieldName']])
99  ) {
100  $result['processedTca']['columns'][$aShowItemFieldArray['fieldName']]['label'] = $aShowItemFieldArray['fieldLabel'];
101  }
102  }
103  }
104  return $result;
105  }
106 
116  protected function setLabelFromPageTsConfig(array $result)
117  {
118  $languageService = $this->getLanguageService();
119  $table = $result['tableName'];
120  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfiguration) {
121  $fieldTSConfig = [];
122  if (isset($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'])
123  && is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'])
124  ) {
125  $fieldTSConfig = $result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.'];
126  }
127  if (!empty($fieldTSConfig['label'])) {
128  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label'];
129  }
130  if (!empty($fieldTSConfig['label.'][$languageService->lang])) {
131  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label.'][$languageService->lang];
132  }
133  }
134  return $result;
135  }
136 
143  protected function translateLabels(array $result)
144  {
145  $languageService = $this->getLanguageService();
146  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfiguration) {
147  if (!isset($fieldConfiguration['label'])) {
148  continue;
149  }
150  $result['processedTca']['columns'][$fieldName]['label'] = $languageService->sL($fieldConfiguration['label']);
151  }
152  return $result;
153  }
154 
158  protected function getLanguageService()
159  {
160  return $GLOBALS['LANG'];
161  }
162 }
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']