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