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
An extra attribute is being created by CKEditor, "data-cke-saved-href", and this carries through into the embed code when you edit a caption with a link. The drupalink plugin has code to clear this out, but it doesn't seem to work with within the caption.
<drupal-entity data-align="left" data-caption="<a data-cke-saved-href="http://www.drupal.org/" href="http://www.drupal.org/">changed caption test</a>" data-embed-button="media" data-entity-embed-display="view_mode:media.full" data-entity-embed-display-settings="" data-entity-type="media" data-entity-uuid="f12a679b-dcc8-414a-a914-bdb1c44f1422" data-langcode="en"></drupal-entity>
- Expected: the property data-cke-saved-href should not perpetuate back into EntityEmbedDialog nor into the drupal-entity embed code.
- Actual: extra property is displaying in both the drupal form EntityEmbedDialog and in the wysiwyg text in the element.
here's a video demonstrating the bug.
https://www.drupal.org/files/issues/2019-06-11/extra_attribute.mov
Steps to reproduce:
Edit the href of a link within the caption of an entity embed within the CKEditor.
Proposed resolution
We can use javascript to traverse the DOM and clean this up before saving the attribute:
+ captionDomNode.querySelectorAll('a').forEach((link) => {
+ link.removeAttribute('data-cke-saved-href');
+ });
Remaining tasks
Review and Commit
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#25 | 3061895-24.patch | 2.92 KB | Wim Leers |
| |||
#25 | 3061895-24-test_only_FAIL.patch | 1.24 KB | Wim Leers |
#21 | 3061895-21.patch | 3.81 KB | Wim Leers |
| |||
#21 | interdiff.txt | 1.89 KB | Wim Leers |
#19 | 3061895-19.patch | 3.3 KB | Wim Leers |
|
Comments
Comment #2
oknateComment #3
oknateComment #4
Wim LeersReproduced.
Comment #5
oknateComment #6
oknateTagging the original issue as related. It will help us add steps to reproduce.
Comment #7
oknateComment #8
oknateComment #9
oknateHere's an initial patch. It seems to do the trick.
Comment #10
oknateComment #11
oknateComment #14
oknateHere's two updated patches, a fix only patch demonstrating the bug and a patch with the test coverage and fix.
Comment #16
oknateComment #17
oknateComment #18
oknateComment #19
Wim LeersHere is a different solution, that doesn't require hardcoding any of this logic; it relies on CKEditor's Advanced Content Filter (rather than reading the DOM, it now reads the post-ACF filtering representation).
Comment #20
oknateI tested manually and it works, and it's more elegant. Plus it passes the functional javascript test. RTBC.
Comment #21
Wim LeersClean-up.
Comment #22
Wim LeersRather than doing this, we should be using the
DrupalLink
button but we can't due to #3062034: `href` in caption editable not updating when using DrupalLink. So postponing this on that.Also improving title.
Comment #23
oknateI was just going to suggest you look at that one before committing. The test cases conflict.
Comment #24
oknateNow with #3062034: `href` in caption editable not updating when using DrupalLink fixed, the test case here needs to be reworked.
Comment #25
Wim LeersWas already doing exactly that :)
#3062034: `href` in caption editable not updating when using DrupalLink just got committed. Rerolling this.
Comment #27
oknateGreat, looks perfect.
Comment #28
Wim LeersAgreed! 🚢