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.
Updated: Comment #0
Problem/Motivation
- upload + insert an image
- replace it with another image
- it will appear as having changed in the CKEditor iframe, but if you switch to source mode, you'll notice that it actually hasn't changed
Proposed resolution
Fix it.
Remaining tasks
Fix it.
User interface changes
None.
API changes
None.
Related Issues
From #1932652-92: Add image uploading to WYSIWYGs through editor.module:
Jesse Beach found a huge bug.
- upload + insert an image
- replace it with another image
- it will appear as having changed in the CKEditor iframe, but if you switch to source mode, you'll notice that it actually hasn't changed
Comment | File | Size | Author |
---|---|---|---|
#10 | cke_cannot_edit_links_or_images-2071957-10.patch | 5.32 KB | Wim Leers |
#10 | interdiff.txt | 1.91 KB | Wim Leers |
#5 | cke_cannot_edit_links_or_images-2071957-5.patch | 4.26 KB | Wim Leers |
#5 | interdiff.txt | 3.03 KB | Wim Leers |
#3 | cke_cannot_edit_links_or_images-2071957-2.patch | 1.94 KB | Wim Leers |
Comments
Comment #1
Wim LeersThis also applies to the link dialog. This is both sad and fortunate at the same time: sad because it's the same problem, fortunate because the code uses the same API calls, so if it worked there, it'd be more mysterious.
Comment #2
catchThis is major at best.
Comment #3
Wim LeersApparently there is a magical, undocumented
data-cke-saved-ATTRIBUTENAME
thing you have to do. I found this only by talking to the CKEditor developers. They are going to document this.Comment #4
Wim LeersCrosspost.
Comment #5
Wim LeersThe CKEditor developers reviewed the code in #3 and found a problem with it.
The whole reason they are using this
data-cke-saved-ATTRIBUTENAME
thing is because browsers sometimes modify certain attribute values. For example the anchor'shref
and the image'ssrc
attributes contain URLs, and browsers may expand relative URLs to full URLs. IE has been known to modify an anchor'sname
attribute as well apparently.Please verify that this works when reviewing (citing Wiktor Walc, CKEditor CTO):
(In other words, ensure that the drupallink and drupalimage plugins ignore any
foo
attribute for which there is an equivalentdata-cke-saved-foo
attribute.)Also: you needn't worry, no
data-cke-saved-SOMETHING
attribute is ever allowed to end up in the resulting HTML.Comment #6
Wim LeersNote that all this was reviewed by the CKEditor developers for correctness. So I think it should be fine if somebody can just confirm that this indeed fixes the problems :)
Comment #7
Bojhan CreditAttribution: Bojhan commentedTested on simplytest.me can confirm it worked
Comment #8
Bojhan CreditAttribution: Bojhan commentedComment #9
jessebeach CreditAttribution: jessebeach commentedI tested changing an image on a node form. That works now.
I also tested in-place editing. Changing an image through the CKEditor on the front-end results in no change to the image on the entity. After talking with Wim, we believe this is due to the CKEditor not firing a change event when the image attributes are altered; or, it is firing an event and we're just not listening for it in the Edit code.
The code Wim wrote solves the underlying issue in this thread. The problem I uncovered is one of bubbling the change up to the code introduced in this issue.
Comment #10
Wim LeersThe root cause was that no
change
event was being triggered. At first I thought CKEditor itself was at fault, but then I realized this might have something to do with our custom link/image plugins.So I started looking at CKEditor's own plugins. I noticed that all of them had two
calls: one before making the change (because the user might have typed changed) and one after making the change (because the plugin has modified some of the HTML)
Our custom plugins were missing the second call to
editor.fire('saveSnapshot');
. This must've slipped through the cracks when quicksketch originally wrote this.Note: the reason it worked fine on the back-end form is that there, the end result is saved; we don't listen to CKEditor's change event there, because there is no need to.
Comment #11
Wim LeersAlso: great find Jesse :)
Comment #12
Bojhan CreditAttribution: Bojhan commentedAh, doh - didn't check inline editing. Still has to become part of my mental model to check that too :)
Comment #13
jessebeach CreditAttribution: jessebeach commentedCode changes look good. Awesome find Wim! I tested in-place editing and node form editing. Both are working beautifully now.
Comment #14
webchickAwesome, that works!
Committed and pushed to 8.x. Thanks!
Comment #15
Wim Leers.