TYPO3  7.6
TcaColumnsProcessShowitem.php
Go to the documentation of this file.
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 
19 
24 {
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  $addShowItemFieldsToColumnsToProcess = true;
51  if ($result['isInlineChild']) {
52  // If the record is an inline child that is not expanded, it is not necessary to calculate all fields
53  $isExistingRecord = $result['command'] === 'edit';
54  $inlineConfig = $result['inlineParentConfig'];
55  $collapseAll = isset($inlineConfig['appearance']['collapseAll']) && $inlineConfig['appearance']['collapseAll'];
56  $expandCollapseStateArray = $result['inlineExpandCollapseStateArray'];
57  $foreignTable = $result['inlineParentConfig']['foreign_table'];
58  $isExpandedByUcState = isset($expandCollapseStateArray[$foreignTable])
59  && is_array($expandCollapseStateArray[$foreignTable])
60  && in_array($result['databaseRow']['uid'], $expandCollapseStateArray[$foreignTable]) !== false;
61  if ($isExistingRecord && ($collapseAll || !$isExpandedByUcState) && !$result['isInlineAjaxOpeningContext']) {
62  $addShowItemFieldsToColumnsToProcess = false;
63  }
64  }
65 
66  if (!$addShowItemFieldsToColumnsToProcess) {
67  return $result;
68  }
69 
70  $showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
71  $showItemFieldArray = GeneralUtility::trimExplode(',', $showItemFieldString, true);
72 
73  foreach ($showItemFieldArray as $fieldConfigurationString) {
74  $fieldConfigurationArray = GeneralUtility::trimExplode(';', $fieldConfigurationString);
75  $fieldName = $fieldConfigurationArray[0];
76  if ($fieldName === '--div--') {
77  continue;
78  }
79  if ($fieldName === '--palette--') {
80  if (isset($fieldConfigurationArray[2])) {
81  $paletteName = $fieldConfigurationArray[2];
82  if (!empty($result['processedTca']['palettes'][$paletteName]['showitem'])) {
83  $paletteFields = GeneralUtility::trimExplode(',', $result['processedTca']['palettes'][$paletteName]['showitem'], true);
84  foreach ($paletteFields as $paletteFieldConfiguration) {
85  $paletteFieldConfigurationArray = GeneralUtility::trimExplode(';', $paletteFieldConfiguration);
86  $result['columnsToProcess'][] = $paletteFieldConfigurationArray[0];
87  }
88  }
89  }
90  } else {
91  $result['columnsToProcess'][] = $fieldName;
92  }
93  }
94 
95  return $result;
96  }
97 }