Hi, I made a page callback to embed a node form into a ctools modal box. The problem is, the Wysiwyg is not showing on the body field.

Here's the code :

<?php
/**
* A modal node/add callback.
*/
function my_module_ajax_node() {
  global
$user;
 
ctools_include('modal');
 
ctools_include('ajax');
 
$node = (object) array(
     
'uid' => $user->uid,
     
'name' => (isset($user->name) ? $user->name : ''),
     
'type' => 'my_node_type',
     
'language' => LANGUAGE_NONE
     
);
 
$form_state = array(
     
'title' => 'Create a node',
     
'ajax' => TRUE,
     
'build_info' => array(
         
'args' => array($node),
          ),
      );
 
form_load_include($form_state, 'inc', 'node', 'node.pages');
 
$output = ctools_modal_form_wrapper('my_node_type_node_form', $form_state);
  print
ajax_render($output);
  exit;
}
?>

Have you some suggestions about this bug?

Thank you a lot.

Files: 
CommentFileSizeAuthor
#7 ckeditor_ctools.patch402 bytesomerida

Comments

Version:7.x-1.0-rc1» 7.x-1.x-dev

I am running into this issue as well running the latest dev. here is my code for the ctools modal, nothing particularly daunting.

<?php
function guided_tour_create_object_reference($parent_node, $field_name, $node = null) {
    global
$user;
   
ctools_include('modal');
   
module_load_include('inc', 'node', 'node.pages');
    if (!
$node) {
       
$node = new stdClass;
       
$node->type = 'guided_tour_overlay';
       
$node->name = $user->name;
       
$node->language = LANGUAGE_NONE;
       
node_object_prepare($node);
    }  
   
$form_state = array(
       
'ajax'  => TRUE,
       
'title' => t('Guided Tour'),
       
'build_info' => array(
           
'args'  => array($node),
        ),
    ); 
   
$output = ctools_modal_form_wrapper('guided_tour_overlay_node_form', $form_state);
    print
ajax_render($output);
    exit();
}
?>

The error that gets reported in the javascript console is as follows:

Uncaught SyntaxError: Unexpected token < en.js:1
Uncaught TypeError: Cannot read property 'options' of undefined overlay:50
Resource interpreted as Stylesheet but transferred with MIME type text/html: "/node/310/edit/skins/kama/editor.css?t=C3HA5RM". overlay:16

it is trying to include lang/en.js from the url of the page, same with the editor css as you can see above in the error. So the basePath is getting overridden somewhere. Checking CKEDITOR.basePath in the console yeilds the following

CKEDITOR.basePath
"/node/310/edit/"

Project:Chaos tool suite (ctools)» Wysiwyg
Version:7.x-1.x-dev» 7.x-2.x-dev

Moved to wysiwyg module as the error most likely exists there

It looks like whatever is adding that CSS file is doing so with a relative URL, but because it's happening during AJAX, the relative URL is not what is expected, perhaps?

I suspect it is something of that nature. still digging thru wysiwyg code to figure out how it is all added. Installed the ckeditor module and it works just fine, thus my suspicion is that the issue lies in wysiwyg somewhere.

StatusFileSize
new696 bytes

still looking at this with no such luck yet. attached is a test module to reproduce the issue.

Status:Active» Closed (duplicate)

Looks like this is related to how the editor is loaded by wysiwyg. I had remembered that at one point there was another site I had worked on where ckeditor worked in a modal and it dawned on me that I had to patch wysiwyg for it to work. The patch from #356480: Lazy-load editors resolves this issue.

StatusFileSize
new402 bytes

I ran into this issue where the CKEditor did not initialize within a ctools modal. I fixed by checking if the instance exists first. Attached is a patch.

Chrome console showed an error stating "Error: uncaught exception: [CKEDITOR.editor] The instance "EDITOR_ID" already exists."

Thank you omerida, I was close !

You're welcome!

Issue summary:View changes
Status:Closed (duplicate)» Needs review

This bug does not seem to be fixed for me, using latest ctools and wysiwyg dev versions.
Patch in #7 solved it.

Status:Needs review» Postponed (maintainer needs more info)

The patch in #7 destroys any existing instances attached to a field the editor should be [re-]attached to.

This is simply the wrong approach to fixing the problem since the instance shouldn't exist at all. Either something else created it (could happen if also using the standalone ckeditor.module), or it was not previously destroyed when the field it belongs to was updated or removed (someone forgot to detach Drupal behaviors, or we missed such an event).

I'm afraid destroying an existing editor instance before attaching a new one could result in old content (stored in the editor instance) could replace the contents of the field before the new instance is attached, potentially removing any changes made since the elements belonging to the previous editor instance were removed.

Can you give specific instructions on how to reproduce this issue?
Is the Panels-In-Place-Editor involved?
Is it only happening for some modals?
Can you reproduce it using the test module in #5?
Was there another node form outside/behind the modal?
Which field(s) was the editor active on?
Was an editor instance actually visible when the error happened, or had there previously been a visible editor instance on the a field, but it disappeared when performing a certain action?

Status:Postponed (maintainer needs more info)» Needs review

Can you give specific instructions on how to reproduce this issue?
Node form with wysiwyg enabled field and file upload file, loaded in a modal
After uploading file, the wysiwyg field textarea disappears, with this error
Uncaught [CKEDITOR.editor.replace] The element with id or name "edit-field-description-und-0-value" was not found

Is the Panels-In-Place-Editor involved?
No

Is it only happening for some modals?
All with given scenario

Can you reproduce it using the test module in #5?
Haven't tried yet

Was there another node form outside/behind the modal?
Yes, a different node form with no naming clashes

Which field(s) was the editor active on?
The field 'description'

Was an editor instance actually visible when the error happened, or had there previously been a visible editor instance on the a field, but it disappeared when performing a certain action?
Yes, this exactly describes the problem. The trigger was a file upload, using regular core file fields.

And yes, #7 "fixes" the problem for me.

The theory about someone not calling detachBehaviors sound plausible, I'll look into that

Okay, detach is being called properly, but for some reason the file/ajax callback is not being triggered, and it is instead re-rendering the whole modal. When it renders the modal, CTools calls attachBehaviors again.

So one solution is to call detachBehaviors before rerendering.
The other is to fix the file ajax upload to actually work as intended.

Not sure if this is the same for everyone here, but it describes my issue.

Part of this was my own doing, but #2215857: Behaviors get attached to removed forms and #1907256: modal_display should detach before updating dom were needed to fix it completely.