From 13d55a0c8ef16514a36b8b2864fb039f86af3026 Mon Sep 17 00:00:00 2001 From: Stefan Froemken Date: Tue, 9 May 2023 09:11:04 +0200 Subject: [PATCH] [BUGFIX] Respect multiple classes in CKEditor5 allowedClasses migrator While migrating CKEditor5 property buttons.link.properties.class.allowedClasses the CKEditor5Migrator will now respect multiple classes. Resolves: #100841 Releases: main, 12.4 Change-Id: I245e8b0c8b2d14ee7917471963f29a9d65480245 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81333 Reviewed-by: Benjamin Franzke Tested-by: core-ci Tested-by: Benjamin Franzke --- .../Classes/Configuration/CKEditor5Migrator.php | 15 ++++++++------- .../Unit/Configuration/CKEditor5MigratorTest.php | 9 +++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php b/typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php index 66e7d7b16bc4..bcc23bf7c26f 100644 --- a/typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php +++ b/typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php @@ -719,7 +719,7 @@ protected function addLinkClassesToStyleSets(): void // Ensure editor.config.style.definitions exists $this->configuration['editor']['config']['style']['definitions'] ??= []; - $allowedClasses = is_array($this->configuration['buttons']['link']['properties']['class']['allowedClasses']) + $allowedClassSets = is_array($this->configuration['buttons']['link']['properties']['class']['allowedClasses']) ? $this->configuration['buttons']['link']['properties']['class']['allowedClasses'] : GeneralUtility::trimExplode(',', $this->configuration['buttons']['link']['properties']['class']['allowedClasses'], true); @@ -731,19 +731,20 @@ protected function addLinkClassesToStyleSets(): void } } - foreach ($allowedClasses as $allowedClass) { + foreach ($allowedClassSets as $classSet) { + $allowedClasses = GeneralUtility::trimExplode(' ', $classSet); foreach ($this->configuration['editor']['config']['style']['definitions'] as $styleSetDefinition) { - if ($styleSetDefinition['element'] === 'a' && $styleSetDefinition['classes'] === [$allowedClass]) { - // allowedClass is already configured, continue with next one + if ($styleSetDefinition['element'] === 'a' && $styleSetDefinition['classes'] === $allowedClasses) { + // allowedClasses is already configured, continue with next one continue 2; } } - // We're still here, this means $allowedClass wasn't found + // We're still here, this means $allowedClasses wasn't found array_splice($this->configuration['editor']['config']['style']['definitions'], $indexToInsertElementsAt, 0, [[ - 'classes' => [$allowedClass], + 'classes' => $allowedClasses, 'element' => 'a', - 'name' => $allowedClass, // we lack a human-readable name here... + 'name' => implode(' ', $allowedClasses), // we lack a human-readable name here... ]]); $indexToInsertElementsAt++; } diff --git a/typo3/sysext/core/Tests/Unit/Configuration/CKEditor5MigratorTest.php b/typo3/sysext/core/Tests/Unit/Configuration/CKEditor5MigratorTest.php index e826bbd2acdd..d31f96f35901 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/CKEditor5MigratorTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/CKEditor5MigratorTest.php @@ -1557,7 +1557,7 @@ public static function migrationDataProvider(): array 'link' => [ 'properties' => [ 'class' => [ - 'allowedClasses' => 'link-arrow, link-chevron, class-karl', + 'allowedClasses' => 'link-arrow, btn btn-default, link-chevron, class-karl', ], ], ], @@ -1573,6 +1573,11 @@ public static function migrationDataProvider(): array 'element' => 'a', 'name' => 'Link Arrow', ], + [ + 'classes' => ['btn', 'btn-default'], + 'element' => 'a', + 'name' => 'btn btn-default', + ], [ 'classes' => ['link-chevron'], 'element' => 'a', @@ -1616,7 +1621,7 @@ public static function migrationDataProvider(): array 'link' => [ 'properties' => [ 'class' => [ - 'allowedClasses' => 'link-arrow, link-chevron, class-karl', + 'allowedClasses' => 'link-arrow, btn btn-default, link-chevron, class-karl', ], ], ],