‪TYPO3CMS  10.4
TcaTypesShowitem.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 {
34  protected ‪$processedTca;
35 
42  public function ‪addData(array $result)
43  {
44  $this->processedTca = $result['processedTca'];
45 
46  $recordTypeValue = $result['recordTypeValue'];
47 
48  // Handle subtype_value_field, subtypes_addlist, subtypes_excludelist
49  if (!empty($result['processedTca']['types'][$recordTypeValue]['subtype_value_field'])) {
50  $subtypeFieldName = $result['processedTca']['types'][$recordTypeValue]['subtype_value_field'];
51  if (array_key_exists($subtypeFieldName, $result['databaseRow'])) {
52  $subtypeValue = $result['databaseRow'][$subtypeFieldName];
53  $result = $this->‪addFieldsBySubtypeAddList($result, $subtypeFieldName, $subtypeValue, $recordTypeValue);
54  $result = $this->‪removeFieldsBySubtypeExcludeList($result, $subtypeValue, $recordTypeValue);
55  }
56  }
57 
58  // Handle bitmask_value_field, bitmask_excludelist_bits
59  if (!empty($result['processedTca']['types'][$recordTypeValue]['bitmask_value_field'])
60  && isset($result['processedTca']['types'][$recordTypeValue]['bitmask_excludelist_bits'])
61  && is_array($result['processedTca']['types'][$recordTypeValue]['bitmask_excludelist_bits'])
62  ) {
63  $bitmaskFieldName = $result['processedTca']['types'][$recordTypeValue]['bitmask_value_field'];
64  if (array_key_exists($bitmaskFieldName, $result['databaseRow'])) {
65  $bitmaskValue = $result['databaseRow'][$bitmaskFieldName];
66  $result = $this->‪removeFieldsByBitmaskExcludeBits($result, $bitmaskValue, $recordTypeValue);
67  }
68  }
69 
70  // Handling of these parameters is finished. Unset them to not allow other handlers to fiddle with it.
71  // unset does not throw notice, even if not set
72  unset($result['processedTca']['types'][$recordTypeValue]['subtype_value_field']);
73  unset($result['processedTca']['types'][$recordTypeValue]['subtypes_excludelist']);
74  unset($result['processedTca']['types'][$recordTypeValue]['subtypes_addlist']);
75  unset($result['processedTca']['types'][$recordTypeValue]['bitmask_value_field']);
76  unset($result['processedTca']['types'][$recordTypeValue]['bitmask_excludelist_bits']);
77 
78  return $result;
79  }
80 
97  protected function ‪addFieldsBySubtypeAddList(array $result, $subtypeFieldName, $subtypeValue, $recordTypeValue)
98  {
99  if (!empty($this->processedTca['types'][$recordTypeValue]['subtypes_addlist'][$subtypeValue])
100  && is_string($this->processedTca['types'][$recordTypeValue]['subtypes_addlist'][$subtypeValue])
101  ) {
102  $addListString = $this->processedTca['types'][$recordTypeValue]['subtypes_addlist'][$subtypeValue];
103  $addListArray = ‪GeneralUtility::trimExplode(',', $addListString, true);
104  $showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
105  $showItemFieldArray = ‪GeneralUtility::trimExplode(',', $showItemFieldString, true);
106  // The "new" fields should be added after the subtype field itself, so find it
107  foreach ($showItemFieldArray as $index => $fieldConfigurationString) {
108  $found = false;
109  $fieldConfigurationArray = ‪GeneralUtility::trimExplode(';', $fieldConfigurationString);
110  $fieldName = $fieldConfigurationArray[0];
111  if ($fieldName === $subtypeFieldName) {
112  // Found the subtype value field in showitem
113  $found = true;
114  } elseif ($fieldName === '--palette--') {
115  // Try to find subtype value field in palette
116  if (isset($fieldConfigurationArray[2])) {
117  $paletteName = $fieldConfigurationArray[2];
118  if (!empty($this->processedTca['palettes'][$paletteName]['showitem'])) {
119  $paletteFields = ‪GeneralUtility::trimExplode(',', $this->processedTca['palettes'][$paletteName]['showitem'], true);
120  foreach ($paletteFields as $paletteFieldConfiguration) {
121  $paletteFieldConfigurationArray = ‪GeneralUtility::trimExplode(';', $paletteFieldConfiguration);
122  if ($paletteFieldConfigurationArray[0] === $subtypeFieldName) {
123  // Found it in palette
124  $found = true;
125  break;
126  }
127  }
128  }
129  }
130  }
131  if ($found) {
132  // Add fields between subtype field and next element
133  array_splice($showItemFieldArray, $index + 1, 0, $addListArray);
134  break;
135  }
136  }
137  $result['processedTca']['types'][$recordTypeValue]['showitem'] = implode(',', $showItemFieldArray);
138  }
139  return $result;
140  }
141 
157  protected function ‪removeFieldsBySubtypeExcludeList(array $result, $subtypeValue, $recordTypeValue)
158  {
159  if (!empty($this->processedTca['types'][$recordTypeValue]['subtypes_excludelist'][$subtypeValue])
160  && is_string($this->processedTca['types'][$recordTypeValue]['subtypes_excludelist'][$subtypeValue])
161  ) {
162  $removeListString = $this->processedTca['types'][$recordTypeValue]['subtypes_excludelist'][$subtypeValue];
163  $removeListArray = ‪GeneralUtility::trimExplode(',', $removeListString, true);
164  $result = $this->‪removeFields($result, $removeListArray, $recordTypeValue);
165  $result = $this->‪removeFieldsFromPalettes($result, $removeListArray);
166  }
167  return $result;
168  }
169 
185  protected function ‪removeFieldsByBitmaskExcludeBits(array $result, $bitmaskValue, $recordTypeValue)
186  {
187  $removeListArray = [];
188  $bitmaskValue = ‪MathUtility::forceIntegerInRange($bitmaskValue, 0);
189  $excludeListBitsArray = $this->processedTca['types'][$recordTypeValue]['bitmask_excludelist_bits'];
190  foreach ($excludeListBitsArray as $bitKey => $excludeList) {
191  $bitKey = (int)$bitKey;
192  $isNegative = (bool)($bitKey < 0);
193  $bit = abs($bitKey);
194  if (!$isNegative && ($bitmaskValue & 2 ** $bit)
195  || $isNegative && !($bitmaskValue & 2 ** $bit)
196  ) {
197  $removeListArray = array_merge($removeListArray, ‪GeneralUtility::trimExplode(',', $excludeList, true));
198  }
199  }
200  $result = $this->‪removeFields($result, $removeListArray, $recordTypeValue);
201  return $this->‪removeFieldsFromPalettes($result, $removeListArray);
202  }
203 
212  protected function ‪removeFields(array $result, array $removeListArray, $recordTypeValue)
213  {
214  $newFieldList = [];
215  $showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
216  $showItemFieldArray = ‪GeneralUtility::trimExplode(',', $showItemFieldString, true);
217  foreach ($showItemFieldArray as $fieldConfigurationString) {
218  $fieldConfigurationArray = ‪GeneralUtility::trimExplode(';', $fieldConfigurationString);
219  $fieldName = $fieldConfigurationArray[0];
220  if (!in_array($fieldConfigurationArray[0], $removeListArray, true)
221  // It does not make sense to exclude --palette-- and --div--
222  || $fieldName === '--palette--' || $fieldName === '--div--'
223  ) {
224  $newFieldList[] = $fieldConfigurationString;
225  }
226  }
227  $result['processedTca']['types'][$recordTypeValue]['showitem'] = implode(',', $newFieldList);
228  return $result;
229  }
230 
239  protected function ‪removeFieldsFromPalettes(array $result, $removeListArray)
240  {
241  if (isset($result['processedTca']['palettes']) && is_array($result['processedTca']['palettes'])) {
242  foreach ($result['processedTca']['palettes'] as $paletteName => $paletteArray) {
243  if (!isset($paletteArray['showitem']) || !is_string($paletteArray['showitem'])) {
244  throw new \UnexpectedValueException(
245  'showitem field of palette ' . $paletteName . ' in table ' . $result['tableName'] . ' not found or not a string',
246  1439925240
247  );
248  }
249  $showItemFieldString = $paletteArray['showitem'];
250  $showItemFieldArray = ‪GeneralUtility::trimExplode(',', $showItemFieldString, true);
251  $newFieldList = [];
252  foreach ($showItemFieldArray as $fieldConfigurationString) {
253  $fieldConfigurationArray = ‪GeneralUtility::trimExplode(';', $fieldConfigurationString);
254  $fieldName = $fieldConfigurationArray[0];
255  if (!in_array($fieldConfigurationArray[0], $removeListArray, true)
256  || $fieldName === '--linebreak--'
257  ) {
258  $newFieldList[] = $fieldConfigurationString;
259  }
260  }
261  $result['processedTca']['palettes'][$paletteName]['showitem'] = implode(',', $newFieldList);
262  }
263  }
264  return $result;
265  }
266 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\removeFieldsByBitmaskExcludeBits
‪array removeFieldsByBitmaskExcludeBits(array $result, $bitmaskValue, $recordTypeValue)
Definition: TcaTypesShowitem.php:184
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\addFieldsBySubtypeAddList
‪array addFieldsBySubtypeAddList(array $result, $subtypeFieldName, $subtypeValue, $recordTypeValue)
Definition: TcaTypesShowitem.php:96
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem
Definition: TcaTypesShowitem.php:28
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\addData
‪array addData(array $result)
Definition: TcaTypesShowitem.php:41
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪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
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\removeFieldsBySubtypeExcludeList
‪array removeFieldsBySubtypeExcludeList(array $result, $subtypeValue, $recordTypeValue)
Definition: TcaTypesShowitem.php:156
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\$processedTca
‪array $processedTca
Definition: TcaTypesShowitem.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\removeFieldsFromPalettes
‪array removeFieldsFromPalettes(array $result, $removeListArray)
Definition: TcaTypesShowitem.php:238
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem\removeFields
‪array removeFields(array $result, array $removeListArray, $recordTypeValue)
Definition: TcaTypesShowitem.php:211