From fdf349703a126ae57249ce8e5740f673f3e654c6 Mon Sep 17 00:00:00 2001 From: Torben Hansen <derhansen@gmail.com> Date: Wed, 20 Sep 2023 08:36:40 +0200 Subject: [PATCH] [BUGFIX] Allow multiple CSS classes in link browser again When a link is selected in CKEditor 5, the class `ck-link_selected` is added to the link. This caused the link browser to not show the selected class, which has been fixed with #101436. The bugfix does however not consider, that a CSS class in link browser can consist of a string with multiple classes separated by a space. This change ensures, that the link browser again accepts a class string containing multiple class names and shows the selected class string in the CSS-Class select field. Resolves: #101959 Related: #101436 Releases: main, 12.4 Signed-off-by: Torben Hansen <derhansen@gmail.com> Change-Id: I278df61e035073a54ba176955141593c7cd9f3cf Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81092 Tested-by: Benjamin Franzke <ben@bnf.dev> Reviewed-by: Andreas Nedbal <andy@pixelde.su> Reviewed-by: Benjamin Franzke <ben@bnf.dev> Tested-by: Andreas Nedbal <andy@pixelde.su> Tested-by: core-ci <typo3@b13.com> --- .../Classes/Controller/BrowseLinksController.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php index add6bfda7140..b02feb4d449d 100644 --- a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php +++ b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php @@ -160,17 +160,15 @@ class BrowseLinksController extends AbstractLinkBrowserController } if (isset($this->linkAttributeValues['class'])) { // Cleanup current link class value by removing any invalid class, including - // the automatically applied highlighting class `ck-link_selected` and using the - // first allowed class, since only one class can be selected in the link browser! - $allowedClasses = array_intersect( - $classesAnchorArray, - GeneralUtility::trimExplode(' ', $this->linkAttributeValues['class'], true) - ); - if ($allowedClasses !== []) { - $this->linkAttributeValues['class'] = (string)reset($allowedClasses); + // the automatically applied highlighting class `ck-link_selected`. + $linkClass = trim(str_replace('ck-link_selected', '', $this->linkAttributeValues['class'])); + if (in_array($linkClass, $classesAnchorArray, true)) { + $this->linkAttributeValues['class'] = $linkClass; + } else { + unset($this->linkAttributeValues['class']); } if (isset($classesAnchor[$this->displayedLinkHandlerId]) - && !in_array($this->linkAttributeValues['class'], $classesAnchor[$this->displayedLinkHandlerId], true) + && !in_array($linkClass, $classesAnchor[$this->displayedLinkHandlerId], true) ) { unset($this->linkAttributeValues['class']); } -- GitLab