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
<drupal-media>
elements are removed by CKEditor 5 if embed media is disabled even when using Full HTML configuration. With CKEditor 4 the same configuration would retain <drupal-media>
elements.
The same is true for any custom/non-official HTML tag. Only those that have a CKEditor 5 plugin to add support for them can be retained (such as <drupal-media>
), but any/all custom/non-official HTML tags must be retained when a text format+CKEditor 5 are configured to allow arbitrary HTML.
Steps to reproduce
- Create one text format which has media embed and media library enabled
- Create Full HTML text formats for CKEditor 5 and CKEditor 4 and ensure media embed filter is disabled
- Create content that includes
<drupal-media>
using text format that has media embed enabled - Switch to CKEditor 4 Full HTML and ensure that
<drupal-media>
is retained - Switch to CKEditor 5 Full HTML and ensure that
<drupal-media>
is removed
Proposed resolution
Wait for upstream bugfix: https://github.com/ckeditor/ckeditor5/issues/11432
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD
Comment | File | Size | Author |
---|---|---|---|
#24 | interdiff.txt | 836 bytes | lauriii |
#24 | 3268306-24.patch | 2.35 KB | lauriii |
| |||
#21 | interdiff.txt | 1.79 KB | lauriii |
#21 | 3268306-21.patch | 2.21 KB | lauriii |
#19 | 3268306-19.patch | 2.16 KB | lauriii |
Comments
Comment #2
xjmComment #3
Wim LeersWow, this is bad.
Added to #3238333: Roadmap to CKEditor 5 stable in Drupal 9.
So it would seem that
configures GHS to support every HTML element … as long as CKEditor 5 knows about it.
IOW: custom elements are stripped?! 🙈😱
Sadly, yes, reproduced with simply this:
gets converted to
by CKE5. In CKE4, this was kept unchanged.
This feels/sounds similar to #3245950: [upstream] <script> tag support in GHS and #3256566: [upstream] <style> tag support in GHS, which were trivial fixes upstream for them, both using the same approach. Let's hope the same approach works for arbitrary unknown elements 🤞
This is impossible to solve on the Drupal side because Drupal does not and cannot know which HTML elements are being used in a particular piece of rich text. And even if we analyzed a stored piece of rich text, then we still wouldn't be able to predict which additional custom elements would be entered (or pasted) by the user in the future.
Will raise this in Thursday's call with the CKEditor 5 team. Sending them this right away, because this is of the highest possible priority.
Comment #4
Wim LeersUpstream bug report filed: https://github.com/ckeditor/ckeditor5/issues/11432
Comment #5
Wim LeersConfirmed with @lauriii.
Comment #6
Wim Leers⚠️ Was informed by the CKEditor 5 team that this will not be fixed in the April 6 release (https://github.com/ckeditor/ckeditor5/issues/11387), but in the release after that (May).
Comment #7
Wim LeersComment #9
Wim LeersThe issue title makes it sound like this is a bug specific to
<drupal-media>
, but that's not the case. Improved the title + issue summary to clarify the impact scope.Thanks @dom for confirming this problem with
<drupal-entity>
, for which a filter exists (https://www.drupal.org/project/entity_embed), but no CKEditor 5 plugin exists yet, and so no work-around is possible … and simply starting to use CKEditor 5 on a "Full HTML-like" text format that uses the Entity Embed filter will today simply lose all the embedded entities upon editing!Comment #10
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedIn the case of my website, this issue completely prevent any adoption of any Drupal version where CKE5 is the norm.
For that reason, I added Entity Embed in the list of "needs Drupal 10 & CKE5 readiness" tracked at : https://www.drupal.org/node/3273985
Note that because the tag is completely stripped, if a user edits a node with any custom element, the data are lost as the node is saved. If you don't have revisions activated, those data are lost forever.
I would be interested to build an MVP workaround for those modules that users or even the module maintainers could use in the meantime of a proper implementation. That MVP should just register the tag and all it's possible attributes to CKEditor 5 so they are not stripped. Eventually, it could replace it in CKE view (not in save) by a red square marked "no preview available" for instance. If you have instructions, documentation or direction to point for helping on that, it would be great.
Comment #11
Wim LeersWe know, that's why this is a critical data loss bug — the CKEditor team knows this is hard blocker for the CKEditor 5 module from becoming stable.
Thanks for confirming this though, having confirmation from concrete sites also helps convey this to them :) 👍
Comment #13
Wim LeersPer @lauriii: https://github.com/ckeditor/ckeditor5/pull/11744 was merged which should address this stable blocker! 🥳
Comment #14
fagounfortunately the latest ckeditor release does not include the change yet
Comment #15
xjmComment #16
catchThis was released in ckeditor 34.2.0. Not sure what specifically needs to happen in this issue.
Comment #17
catchNo longer blocked on upstream.
Comment #18
Wim Leers… because #3301495: Update CKEditor 5 to 35.0.1 landed 🤓
Comment #19
lauriiiComment #20
Wim LeersManual testing
I wrote this in #3:
But today (thanks to #3301495: Update CKEditor 5 to 35.0.1), it gets converted to:
So … the bug has indeed been fixed upstream! 🥳
Tests
All that remains is test coverage.
@lauriii wrote that in #19.
I'd like this to be expanded slightly: I'd like both
<foo></foo>
, which this alreadyhas
<bar>bar</bar>
, to test the expected behavior for text contents of custom/unofficial tags when switching to a text format that does not allow this custom tag(I expect it to be converted to<p>bar</p>)
Once that's addressed, this is RTBC!
Comment #21
lauriiiGood idea! I did that and added an arbitrary attribute too.
Comment #22
Wim LeersBetter still! 👏
Comment #23
catchIt' very possible I'm missing something, but shouldn't this assertion also check that contents of the foo tag is still there? i.e.:
⬅️✌️➡️
Comment #24
lauriiiGood catch! I think that would be a great addition to the test even though it has more to do with testing CKEditor 5 internals than testing our integration.
Moving back to RTBC since it's a very small change so a committer review on this should be sufficient.
Comment #27
catchOK glad I asked! Worth having even if it just makes the test easier to read.
Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!
Comment #29
Wim LeersWe should still get this committed to
9.4.x
.Comment #30
Wim Leers#24 still applies cleanly to
9.4.x
— queued a test to prove it passes tests.Comment #32
catchCommitted/pushed to 9.4.x, thanks!
Comment #33
Wim LeersRestoring previous status.