Skip to content

Commit

Permalink
[BUGFIX] Respect multiple classes in CKEditor5 allowedClasses migrator
Browse files Browse the repository at this point in the history
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 <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
froemken authored and bnf committed Oct 5, 2023
1 parent ec462b5 commit 13d55a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 8 additions & 7 deletions typo3/sysext/core/Classes/Configuration/CKEditor5Migrator.php
Expand Up @@ -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);

Expand All @@ -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++;
}
Expand Down
Expand Up @@ -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',
],
],
],
Expand All @@ -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',
Expand Down Expand Up @@ -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',
],
],
],
Expand Down

0 comments on commit 13d55a0

Please sign in to comment.