I am using the 'Panels' module to allow my content frame to be divided into areas. When I activate TinyMCE (and add /admin/panels/* to the list of pages on which it will appear) two editor panes appear for each textarea on the page. The code is showing the Javascript which creates the MCE editor twice below the HTML for the textarea. When I collapse the second editor (there are two 'disable rich-text' links) one of the two panes disappears (although the 'disable rich-text' link is still there, unchanged) and I can then enable/disable the remaining box without the second area reappearing. The actual functionality of the module is not affected but it doesn't look too great at the moment. I have seen one other example of a similar problem (http://drupal.org/node/51990) but the option of disabling TinyMCE for this part of the site is not available to me! I have also seen mention of TinyMCE plugins having this effect but I have added no plugins to the TinyMCE install apart from IMCE (and it still happens when that is removed).

Any clues would be most welcome...

Comments

geme4472’s picture

Hello,
I've found the same happens with the comments form of one of my apps. The reason, in that case, is because I use mytheme_comment_form() in my template.php file in order to change some form values. Without testing it out, it looks like tinymce essentially "thinks" that you're invoking another form.

I realize that my comment is theme-related and your issue is module-related, but that's all the information I have.

geme4472’s picture

Forgot to mention. This bug appeared when I moved from 4.7.2 to 4.7.4.

geme4472’s picture

OK, my bad. Nothing to do with my phptemplating... except that in that override function I was using drupal_get_form() (er, something), when I should've been using form_render(). I think my use of the drupal_get_form() was essentially a duplicate effort. I have no idea why I wrote it that way originally!?

graham_king’s picture

This is because in 'panels.module' method 'panels_edit_form' it calls 'form.inc' method 'form_builder' twice - once via the last call to 'panels_form_builder', once via 'drupal_get_form'.
In 'form_builder' it calls all the registered methods for the form element type. If it's a 'textarea' that means the 'tinymce.module' method 'tinymce_process_textarea'. That is where the javascript for 'tinyMCE.init' is inserted. As the method is called twice the js goes in twice, and creates two editors.

It seems like either:

1.the panels module shouldn't be doing the first call to 'panels_form_builder'. Commenting out this line fixed the problem for me:
panels_form_builder($form['content'][$area][$id]['configuration']);
That method does all sorts of other stuff, so I put it back in.

2. Or the tinymce module shouldn't process an element more than once. This is the fix I chose.

In tinymce.module just before the function declaration for tinymce_process_textarea add:

$already_processed = array();

Then inside the function add:

 global $already_processed;
  
  if ( count($already_processed) >= 1 && in_array($element['#id'], $already_processed) ) {
        return $element;
  } 
  $already_processed[] = $element['#id'];

This fixes it for me. I don't know drupal well enough to recommend either solution as a permanent fix.

Graham

darren oh’s picture

Title: Multiple MCE editor textareas appearing on Panels editing page » Multiple toolbars appear in textarea
Status: Active » Reviewed & tested by the community
StatusFileSize
new972 bytes

This problem is caused by a simple coding error. Moving two lines to the run-once-per-request section of tinymce_process_textarea() fixes it.

darren oh’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Component: User interface » Code
darren oh’s picture

StatusFileSize
new1.08 KB

Oops. Previous patch allowed editor to be loaded for only one text area. The attached patch keeps track of each text area separately.

darren oh’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.16 KB

And then I restored the original problem by incorrectly setting a static variable. I think this patch sets the static variable correctly.

darren oh’s picture

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

Status: Reviewed & tested by the community » Needs work

IMHO this looks a bit ugly - why not simply:

    // Load a TinyMCE init once for each textarea.
    static $tinymce_areas = array();
    if (!isset($tinymce_areas[$element['#id']])) {
      if ($init) {
        drupal_add_js($tinymce_invoke, 'inline');
        $tinymce_areas[$element['#id']] = 1;
      }
    }
darren oh’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.05 KB

Updated patch.

sun’s picture

Status: Reviewed & tested by the community » Needs work

We should adhere to Drupal Coding Standards:

if ($init) drupal_add_js($tinymce_invoke, 'inline');
darren oh’s picture

Status: Needs work » Reviewed & tested by the community

I think it's best for a patch to fix just one issue. TinyMCE as a whole does not comply with Drupal coding standards. That should be a separate issue.

matt@antinomia’s picture

Confirmed the bug and the fix. This should be committed.

sun’s picture

TinyMCE module is unmaintained. If this bug still exists in Wysiwyg module, please move this issue to its queue.

pomliane’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

This version of TinyMCE is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.