Updated: Comment #0

Problem/Motivation

  1. upload + insert an image
  2. replace it with another image
  3. 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.

From #1932652-92: Add image uploading to WYSIWYGs through editor.module:

Jesse Beach found a huge bug.

  1. upload + insert an image
  2. replace it with another image
  3. 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
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Title: Cannot change existing images through Text Editor's image dialog » Cannot change existing images or links through Text Editor's image/link dialogs

This 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.

catch’s picture

Priority: Critical » Major

This is major at best.

Wim Leers’s picture

Priority: Major » Critical
Status: Active » Needs review
Issue tags: +quickfix
FileSize
1.94 KB

Apparently 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.

Wim Leers’s picture

Priority: Critical » Major

Crosspost.

Wim Leers’s picture

The 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's href and the image's src attributes contain URLs, and browsers may expand relative URLs to full URLs. IE has been known to modify an anchor's name attribute as well apparently.

Please verify that this works when reviewing (citing Wiktor Walc, CKEditor CTO):

Check CKEditor demo and change in wysiwyg area (in Firebug) the image to e.g.

<img alt="Saturn V carrying Apollo 11" data-cke-saved-src="http://b.cksource.com/a/1/img/samplexyz.jpg" src="http://b.cksource.com/a/1/img/sample.jpg" class="right">

(data-cke-saved-src != src)

Open the Image dialog, You will see that CKEditor will show the following URL in Image dialog: samplexyz.jpg (taken from saved-src)

(In other words, ensure that the drupallink and drupalimage plugins ignore any foo attribute for which there is an equivalent data-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.

Wim Leers’s picture

Note 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 :)

Bojhan’s picture

Tested on simplytest.me can confirm it worked

Bojhan’s picture

Status: Needs review » Reviewed & tested by the community
jessebeach’s picture

Status: Reviewed & tested by the community » Needs work

I 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.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
1.91 KB
5.32 KB

The 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

editor.fire('saveSnapshot');

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.

Wim Leers’s picture

Also: great find Jesse :)

Bojhan’s picture

Ah, doh - didn't check inline editing. Still has to become part of my mental model to check that too :)

jessebeach’s picture

Status: Needs review » Reviewed & tested by the community

Code changes look good. Awesome find Wim! I tested in-place editing and node form editing. Both are working beautifully now.

webchick’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +JavaScript

Awesome, that works!

Committed and pushed to 8.x. Thanks!

Wim Leers’s picture

Issue tags: -sprint

.

Automatically closed -- issue fixed for 2 weeks with no activity.