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.
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 :
/**
* 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.
Comment | File | Size | Author |
---|---|---|---|
#7 | ckeditor_ctools.patch | 402 bytes | omerida |
Comments
Comment #1
cangeceiro CreditAttribution: cangeceiro commentedI am running into this issue as well running the latest dev. here is my code for the ctools modal, nothing particularly daunting.
The error that gets reported in the javascript console is as follows:
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
Comment #2
cangeceiro CreditAttribution: cangeceiro commentedMoved to wysiwyg module as the error most likely exists there
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedIt 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?
Comment #4
cangeceiro CreditAttribution: cangeceiro commentedI 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.
Comment #5
cangeceiro CreditAttribution: cangeceiro commentedstill looking at this with no such luck yet. attached is a test module to reproduce the issue.
Comment #6
cangeceiro CreditAttribution: cangeceiro commentedLooks 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.
Comment #7
omerida CreditAttribution: omerida commentedI 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."
Comment #8
jide CreditAttribution: jide commentedThank you omerida, I was close !
Comment #9
omerida CreditAttribution: omerida commentedYou're welcome!
Comment #10
AaronBaumanThis bug does not seem to be fixed for me, using latest ctools and wysiwyg dev versions.
Patch in #7 solved it.
Comment #11
TwoDThe 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?
Comment #12
tim.plunkettCan 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.
Comment #13
tim.plunkettThe theory about someone not calling detachBehaviors sound plausible, I'll look into that
Comment #14
tim.plunkettOkay, 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.
Comment #15
tim.plunkettPart 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.
Comment #16
TwoDCould you check if just applying #1907256: modal_display should detach before updating dom fixes it together with the current Wysiwyg 7.x-2.x-dev?
I recently comitted #1757684: Ajax error on Add another item as a workaround since the "upstream" Core and CTools issues haven't received much attention yet - other than from @tim.plunkett, thanks for that =)
If so, I think we could close this as a duplicate.
Comment #17
odegard CreditAttribution: odegard commentedI'm a bit behind the curve, but I updated to latest stable ctools (7.x-1.4) and wysiwyg dev (26. june) and now it works for me. No separate patching. No other changes to the system. I tried adding stuff in ckeditor without saving, reloading, tried my best to trip it up but it worked every time.
Comment #18
steinmb CreditAttribution: steinmb as a volunteer and at University Of Bergen commentedRe-reading the issue and linked Ctools issues. Looks to me that there is nothing left to do here.