Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In CKEditor, if...
- You're using the styles dropdown
- You have a style with with multiple classes, then
Then...
This works: p.a-test.b-test|Test
This doesn't: p.b-test.a-test|Test
Because "a" lexicographically comes before "b". A style won't work if its classes aren't sorted alphabetically. This can be a real puzzler, because, well, yeah.
Steps to reproduce:
- Add a new text format
- Configure it to use CKEditor
- Add "Styles" button to your "Active Toolbar"
- Add this "Styles dropdown" entry:
p.b-test.a-test|Test
- Enable "Limit allowed HTML tags and correct faulty HTML"
- Under "Allowed HTML tags", enter
<p class="b-test a-test">
(it might get entered automatically) - Go to create or edit content with a Body field or other long formatted text field
- Switch field's "Text format" to the format you created
- Enter some text (it generates a
<p>
tag) and see that Styles dropdown is greyed out - Change step 4's "Styles dropdown" entry to
p.a-test.b-test|Test
(note the alphabetical ordering) - Repeat steps 7-9 - this time the Styles dropdown works!?
Proposed resolution
Upstream bugfix.
Remaining tasks
Upstream bugfix.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#25 | stylescombo_plugin_not_listed_alphabetically-2710431-25.patch | 761 bytes | matthiasm11 |
#24 | 2710431-24.patch | 675 bytes | weseze |
#23 | 2710431-23.patch | 685 bytes | weseze |
#10 | CKE stylescombo reverse alphabetical classes — FAILS.png | 10.67 KB | Wim Leers |
#10 | CKE stylescombo alphabetical classes — works.png | 10.7 KB | Wim Leers |
Comments
Comment #2
charginghawk CreditAttribution: charginghawk at Genuine commentedComment #3
charginghawk CreditAttribution: charginghawk at Genuine commentedComment #4
charginghawk CreditAttribution: charginghawk at Genuine commentedComment #5
Wim LeersComment #6
Wim LeersWTF, that sounds really bizarre. I'll need to try to reproduce this. This sounds like a bug in CKEditor.
We'll need to narrow it down further to the smallest possible case that still reproduces this.
To clarify: step 11 means this problem is happening randomly?
Comment #7
charginghawk CreditAttribution: charginghawk at Genuine commentedNot random - it's based on whether the classes are sorted alphabetically.
This works:
p.a-test.b-test|Test
This doesn't:
p.b-test.a-test|Test
Because "a" lexicographically comes before "b". In my case, I had
a.o-button.c-button|Link
, and I had to change it toa.c-button.o-button|Link
.I suspect what's going on is there's a sort somewhere. In js, the greater than operator can be used on strings, so maybe that's what's up.
Comment #8
Daltyn CreditAttribution: Daltyn commentedI can confirm this is an issue. The following settings work
a.button|Button
a.beige.button|Beige Button
a.button.expanded|Expanded Button
a.beige.button.expanded|Beige Expanded Button
These do not.
a.button|Button
a.button.beige|Beige Button
a.button.expanded|Expanded Button
a.button.beige.expanded|Beige Expanded Button
Comment #9
charginghawk CreditAttribution: charginghawk at Genuine commentedComment #10
Wim LeersReproduced. WTF! So weird!
This is then also confirmed to be an upstream bug. Assigning to the CKEditor team.
Comment #11
Wim LeersSimplified the steps to reproduce and the issue summary.
Comment #12
Tade0 CreditAttribution: Tade0 at CKSource commentedI managed to reproduce this bug in a standalone CKEditor instance, so this is definitely a CKEditor issue. Preparing a fix for this.
EDIT: you can track the progress of this fix here: https://dev.ckeditor.com/ticket/14909.
Comment #13
charginghawk CreditAttribution: charginghawk at Genuine commentedTade0's linked ticket was closed as a duplicate of: https://dev.ckeditor.com/ticket/13206
Comment #15
kkri CreditAttribution: kkri at Liip for FREITAG lab. AG commentedThis is still an issue as of today, and I would like to share my encounter with this bug.
Here's an other example with special characters that won't work:
a.btn.btn--link.b-color| CTA Extern
Dashes are for some reason considered to be in front of the letters in the alphabet, so I had to move the class "b-color" to the front.
a.b-color.btn.btn--link| CTA Extern
Comment #17
Wim LeersNow on GitHub: https://github.com/ckeditor/ckeditor-dev/issues/727.
Comment #20
Wim LeersSee #2999691-4: Update CKEditor library to 4.10.1, this has been fixed in CKEditor 4.10.1! Please test that patch to verify this has been fixed :)
Comment #21
weseze CreditAttribution: weseze as a volunteer commentedThis bug is still present in ckeditor 4.10.1. Jus tested on D8.6.4 with ckeditor 4.10.1 included.
Comment #22
weseze CreditAttribution: weseze as a volunteer commentedIt also seems that (for us at leaset) this problem only started after we update to a Drupal version which had ckeditor 4.10.1. Before it did work properly.
Comment #23
weseze CreditAttribution: weseze as a volunteer commentedAttached is a patch that works around the issue by sorting the classes before passing them to drupalSettings.
Comment #24
weseze CreditAttribution: weseze as a volunteer commentedSmall corretion (still had my local paths in the patch)
Comment #25
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedAlthough I think this should be fixed in CKeditor (https://github.com/ckeditor/ckeditor-dev/issues/2578), I'm attaching an improved patch because this will speed up fixing the issue in Drupal.
Only variables should be passed by reference
caused by referencing a function instead of an array in the sort function.Comment #26
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedComment #29
weseze CreditAttribution: weseze as a volunteer commentedI don't think we should include the patch core actually. It changes the order in the list of classes and that might lead to unexpected results. The actual fix should be in ckeditor, comparing classes alphabetically but applying them as given.
The patch here should only be used to quickly work around the issue in cases that allow it.
Comment #35
quietone CreditAttribution: quietone at PreviousNext commentedCKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0