‪TYPO3CMS  10.4
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,
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  if (!empty($fieldTSConfig['label'])) {
130  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label'];
131  }
132  if (!empty($fieldTSConfig['label.'][$languageService->lang])) {
133  $result['processedTca']['columns'][$fieldName]['label'] = $fieldTSConfig['label.'][$languageService->lang];
134  }
135  }
136  return $result;
137  }
138 
145  protected function ‪translateLabels(array $result)
146  {
147  $languageService = $this->‪getLanguageService();
148  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfiguration) {
149  if (!isset($fieldConfiguration['label'])) {
150  continue;
151  }
152  $result['processedTca']['columns'][$fieldName]['label'] = $languageService->sL($fieldConfiguration['label']);
153  }
154  return $result;
155  }
156 
160  protected function ‪getLanguageService()
161  {
162  return ‪$GLOBALS['LANG'];
163  }
164 }
‪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\getLanguageService
‪LanguageService getLanguageService()
Definition: TcaColumnsProcessFieldLabels.php:160
‪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:145
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46