[TASK] Move LanguageService to EXT:core
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FormDataProvider / TcaColumnsProcessShowitem.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\FormDataProvider;
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
17 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Mark columns that are used in showitem or palettes for further processing
22 */
23 class TcaColumnsProcessShowitem implements FormDataProviderInterface
24 {
25 /**
26 * Determine which fields are shown to the user and add those to the list of
27 * columns that must be processed by the next data providers.
28 *
29 * @param array $result
30 * @return array
31 */
32 public function addData(array $result)
33 {
34 $recordTypeValue = $result['recordTypeValue'];
35
36 if (!isset($result['processedTca']['types'][$recordTypeValue]['showitem'])
37 || !is_string($result['processedTca']['types'][$recordTypeValue]['showitem'])
38 ) {
39 throw new \UnexpectedValueException(
40 'No or invalid showitem definition in TCA table ' . $result['tableName'] . ' for type ' . $recordTypeValue,
41 1438614542
42 );
43 }
44
45 if (empty($result['processedTca']['columns'])) {
46 // We are sure this is an array by InitializeProcessedTca data provider
47 return $result;
48 }
49
50 if ($result['isInlineChild'] && !$result['isInlineChildExpanded']) {
51 // If the record is an inline child that is not expanded, it is not necessary to calculate all fields
52 return $result;
53 }
54
55 $showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
56 $showItemFieldArray = GeneralUtility::trimExplode(',', $showItemFieldString, true);
57
58 foreach ($showItemFieldArray as $fieldConfigurationString) {
59 $fieldConfigurationArray = GeneralUtility::trimExplode(';', $fieldConfigurationString);
60 $fieldName = $fieldConfigurationArray[0];
61 if ($fieldName === '--div--') {
62 continue;
63 }
64 if ($fieldName === '--palette--') {
65 if (isset($fieldConfigurationArray[2])) {
66 $paletteName = $fieldConfigurationArray[2];
67 if (!empty($result['processedTca']['palettes'][$paletteName]['showitem'])) {
68 $paletteFields = GeneralUtility::trimExplode(',', $result['processedTca']['palettes'][$paletteName]['showitem'], true);
69 foreach ($paletteFields as $paletteFieldConfiguration) {
70 $paletteFieldConfigurationArray = GeneralUtility::trimExplode(';', $paletteFieldConfiguration);
71 $result['columnsToProcess'][] = $paletteFieldConfigurationArray[0];
72 }
73 }
74 }
75 } else {
76 $result['columnsToProcess'][] = $fieldName;
77 }
78 }
79
80 return $result;
81 }
82 }