On a node edit form, whenever I try to upload in image in an image field, the editor dissapears. The only way to get it back is to toggle the textfield to plain text and then back to "full html". Anybody else having this issue?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kingman1016’s picture

Yes, it also disappears when adding multi value field items.

andraek’s picture

I'm guessing then that it must have something to do with the editor not being re-enabled after the form is updated via ajax?

swati.karande’s picture

FileSize
671 bytes

Hi,
I have attached a small patch for this issue.

andraek’s picture

You are awesome! Thank you!

markabur’s picture

Hm, so WYSIWYG module itself needs to be patched in order to fix this issue? The patch does work, but it seems like CKEditor for WYSIWYG Module is the one with the problem?

Paulmicha’s picture

Project: CKEditor for WYSIWYG Module » Wysiwyg
Version: 7.x-1.x-dev » 7.x-2.2
Component: User interface » Code
Status: Active » Reviewed & tested by the community

Patch in #3 works, thanks a lot !
(Moving this issue in wysiwyg project).

TwoD’s picture

Title: Editor Disapearing » Editor disapearing when uploading image
Component: Code » Editor - CKEditor
Priority: Major » Normal
Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I'm not seeing this issue, the editor doesn't actually get removed on 'serialize' events because those are supposed to enable syncing of contents back to the original textarea (so AJAX operations can serialize up to date form values etc) when other elements in the same form are about to be replaced as a response to an AJAX operation or other DOM manipulations. Thus, the editor should not get replaced in the first place if '#wrapper' was set correctly on the image upload field so it only targets a wrapper of the image field itself.

When I upload an image using the core Image field, the detach() integration method gets called for all instances with trigger='serialize' and thus calls the updateElement() method on the CKEditor instance.
It never calls the destroy() method on any CKEditor instance unless one of the fields which are actually about to be replaced have editor instances on them. Then the instance must be destroyed so it can be recreated on the original textarea which has now been replaced, or you'll get errors about the instance already existing.

The patch won't apply because there are whitespace errors and it's not been created from inside the Wysiwyg folder.
Specifically mentioning Image module in the comment isn't very helpful since any module can tell Drupal to detach behaviors using the 'serialize' trigger at any time.

How did you come up with the patch? What's the reasoning behind not calling detach() when trigger is 'serialize'?

markabur’s picture

@TwoD I've only seen this issue with http://drupal.org/project/wysiwyg_ckeditor -- not the normal ckeditor component that is included with Wysiwyg module.

TwoD’s picture

Project: Wysiwyg » CKEditor for WYSIWYG Module
Version: 7.x-2.2 » 7.x-1.x-dev
Component: Editor - CKEditor » Code

Oh, that makes sense then since wysiwyg_ckeditor doesn't currently check the reason for the detach call and always destroys the editor instance.

http://drupalcode.org/project/wysiwyg_ckeditor.git/blob/refs/heads/7.x-1...

Drupal.wysiwyg.editor.detach.ckeditor_extended = function(context, params) {
 if (typeof params != 'undefined') {
   var instance = CKEDITOR.instances[params.field];
   if (instance) {
     instance.destroy();
   }
 }
 else {
   for (var instanceName in CKEDITOR.instances) {
     CKEDITOR.instances[instanceName].destroy();
   }
 }
};

vs
http://drupalcode.org/project/wysiwyg.git/blob/refs/heads/7.x-2.x:/edito...

Drupal.wysiwyg.editor.detach.ckeditor = function (context, params, trigger) {
  var method = (trigger == 'serialize') ? 'updateElement' : 'destroy';
  if (typeof params != 'undefined') {
    var instance = CKEDITOR.instances[params.field];
    if (instance) {
      instance[method]();
    }
  }
  else {
    for (var instanceName in CKEDITOR.instances) {
      if (CKEDITOR.instances.hasOwnProperty(instanceName)) {
        CKEDITOR.instances[instanceName][method]();
      }
    }
  }
};
Paulmicha’s picture

Title: Editor disapearing when uploading image » Editor gets disabled by ajax calls : detach trigger isn't checked properly
Status: Postponed (maintainer needs more info) » Needs review
FileSize
996 bytes

So if i'm guessing correctly, the proper fix for this issue should be :

swati.karande’s picture

It looks correct and working for me.
Thanks!

rv0’s picture

patch works for me

Paulmicha’s picture

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

I can also confirm that the patch in #10 worked for me.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @Paulmicha! And all testers. Committed.

Status: Fixed » Closed (fixed)

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