From 2d4d333bd84c05460fd734fa59f2e0104338573f Mon Sep 17 00:00:00 2001 From: Nikita Hovratov <nikita.h@live.de> Date: Thu, 5 Sep 2024 20:15:01 +0200 Subject: [PATCH] [BUGFIX] Replace system palettes with labels The label of palettes can be overridden in showitem. These labels are now also removed to correctly find and remove this system palettes. Resolves: #104836 Related: #104814 Releases: main Change-Id: I322ffd71fcc062ad07ff9b59f2f8dd32a381668f Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85902 Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> --- .../Configuration/Tca/TcaPreparation.php | 31 ++++++++++++---- .../Configuration/Tca/TcaPreparationTest.php | 35 +++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php b/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php index d7c9a355cca8..27ab017d7d9c 100644 --- a/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php +++ b/typo3/sysext/core/Classes/Configuration/Tca/TcaPreparation.php @@ -566,14 +566,33 @@ readonly class TcaPreparation private function removeCustomFieldLabels(array $showitemParts, array $fieldList): array { + if ($fieldList === []) { + return $showitemParts; + } foreach ($showitemParts as &$showItem) { - // Check if we deal with a field - if (!str_starts_with($showItem, '--div--') && !str_starts_with($showItem, '--palette--')) { - $parts = GeneralUtility::trimExplode(';', $showItem, true, 2); - // Just keep the first part => the fieldname in case field is defined in the $fieldList - if ($fieldList !== [] && in_array($parts[0], $fieldList, true)) { - $showItem = $parts[0]; + // Tabs keep their labels + if (str_starts_with($showItem, '--div--')) { + continue; + } + // Remove label of palette + if (str_starts_with($showItem, '--palette--')) { + $parts = GeneralUtility::trimExplode(';', $showItem, true, 3); + // Palette without label, continue. + if (count($parts) !== 3) { + continue; } + $paletteName = '--palette--;;' . $parts[2]; + if (in_array($paletteName, $fieldList, true)) { + $showItem = $paletteName; + } + continue; + } + // This must be a field. + $parts = GeneralUtility::trimExplode(';', $showItem, true, 2); + $fieldName = $parts[0]; + // Just keep the first part => the fieldname in case field is defined in the $fieldList + if (in_array($fieldName, $fieldList, true)) { + $showItem = $fieldName; } } return $showitemParts; diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php index 895e4b59e99a..81f0bb97f644 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/Tca/TcaPreparationTest.php @@ -855,6 +855,41 @@ final class TcaPreparationTest extends UnitTestCase --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended ', ]; + yield 'General palette with label already exists' => [ + [ + 'types' => [ + 'header' => [ + 'showitem' => ' + --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general, + --palette--;;headers, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:appearance, + --palette--;;frames, + --palette--;;appearanceLinks, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories, + categories, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended, + ', + ], + ], + ], + ' + --palette--;;general, + --palette--;;headers, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:appearance, + --palette--;;frames, + --palette--;;appearanceLinks, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories, + categories, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language, + --palette--;;language, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, + --palette--;;hidden, + --palette--;;access, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes, + rowDescription, + --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended + ', + ]; yield 'Missing general palette' => [ [ 'palettes' => [ -- GitLab