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
We added support for markup in data-caption
in #3222808: Follow-up for #3201646: markup in image captions is lost. However, we only ever tested data-caption
with data that upcasts into $text
. However, there are examples of valid child elements of <figcaption>
that would upcast into a model element (e.g. <section>
would be a valid child of <figcaption
).
Steps to reproduce
- Create new text format that has Drupal Media + Image captions enabled and add
<section>
to source editable elements - Create content using the new text format
- Embed media to the content and enable captions
- Add
<section>
to thedata-caption
value in source editing - Return back to editing 💥
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#36 | core-3276213-36-9.5.x.patch | 119.39 KB | nod_ |
#35 | core-3276213-35.patch | 119.06 KB | nod_ |
| |||
#31 | core-3276213-31.patch | 4.49 KB | nod_ |
#29 | interdiff-26-29.txt | 3.19 KB | nod_ |
#29 | core-3276213-29.patch | 119.07 KB | nod_ |
|
Comments
Comment #2
Wim LeersDue to #2508421: FilterCaption hard-codes allowed tags, I say this is . Chances of this happening are tiny.
Comment #3
lauriiiShould we at least add test coverage as part of this issue for all of the elements that are currently hard coded as supported? I think all of the elements listed there should work since they all convert to an attribute, but it might make sense to explicitly test that to ensure it remains to be the case.
Comment #4
Wim LeersThat would be prudent, and a nice nice-to-have indeed 🤓
Comment #6
Wim LeersComment #8
Wim LeersA specific concrete case of this was encountered:
<br>
is not allowed right now in the caption, even thoughFilterCaption
explicitly allows it. See #3309204: CKEditor 5 crashes with <br> inside of data-caption for details + failing test. Crediting @mherchel for that.Bumping to
because this constitutes a regression compared to CKEditor 4.Comment #10
Wim LeersPer @longwave in Slack, this is potentially related to #2441811-69: Upgrade filter system to HTML5.
Comment #12
nod_Failing test, not quite sure how to actually fix the problem.
Comment #13
nod_Comment #14
nod_Comment #15
nod_Comment #17
nod_Thought it was upstream issue, doesn't appear so :/
Comment #18
Wim LeersWell … that's a good thing 🤓 That means we can fix it! 😜
I bet it's a bug in
I wonder if it's simply the fact that some elements are not allowed to exist in those places, because that's what #3309204-5: CKEditor 5 crashes with <br> inside of data-caption's stack trace suggests:
Comment #19
nod_Thanks to some help from the CKE folks we have a fix. https://github.com/ckeditor/ckeditor5/pull/12798
Comment #21
Wim LeersThat was fast! :O
Comment #22
nod_only updated the image plugin, not the drupal media one.
Added test for the image plugin + update code for the drupal media plugin
Comment #24
nod_Comment #25
Wim LeersQueued
10.0
,9.5
and9.4
tests of #24.So … was the problem that there were two distinct document fragments, and nodes cannot be moved from one document fragment to another?
🤔 What is the purpose of this new test?
Why isn't
\Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testEditableCaption()
adequate?The Media Library plugin is just for inserting, the Media plugin is the one that provides this functionality. So this new test is IMHO at the very least in the wrong test class 😅
Comment #26
nod_1. So I don't have 100% grasp on the cke5 code, but I think transforming text into nodes behaves differently based on the context in which it happens. Context was an empty document fragment before, now it's the caption element. Somehow somewhere it's the right thing to do.
2. no idea 🤷 :D
Updated the test location.
Comment #27
Wim LeersI'd rather just add a
<br>
to the existing\Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testEditableCaption()
test … 😅 These tests are relatively slow, no need for repeating 99% of the test, if we can test both aspects at the same time!Comment #28
nod_It wasn't straightforward so went this way to keep it green will try again later today
Comment #29
nod_Easier after some sleep
Comment #30
Wim LeersGreat! Could you also upload a failing test-only patch, now that the test coverage is just updating an existing test? 🙏
Comment #31
nod_Failing test
Comment #33
nod_Comment #34
Wim LeersPerfect! 👏
which is the first assertion after setting a
data-caption
containing a<br>
, hence #31's failure proves that the green test result for #29 can be trusted! 👍Comment #35
nod_rerolled
crediting wim for review and lauriii for actually finding the fix
Comment #36
nod_the 9.5 version
Comment #39
alexpottCommitted and pushed 8b1819bf3b to 10.1.x and 10544d8d07 to 10.0.x. Thanks!
Committed and pushed afc43ea00f to 9.5.x and c62e7d1c80 to 9.4.x. Thanks!