0
votes

Drupal 7 with TinyMCE included via the Wysiwyg module. "Paste" is enabled in the Wysiwyg config screen. The editor is in general working fine, but now I'm attempting to modify TinyMCE's paste feature to strip all attributes from HTML tags. (Client requirement, don't ask.)

Have added the following to the module file:

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
    if ($context['profile']->editor == 'tinymce') {
        drupal_add_js(drupal_get_path('module', 'MYMODULE').'/js/tinymce_callbacks.js');

        $settings['paste_preprocess'] = 'MYMODULE_tinymce_paste_preprocess_callback';
    }
}

and have created tinymce_callbacks.js with the following contents:

function MYMODULE_tinymce_paste_preprocess_callback(pl, o) {
    alert(o.content);
    o.content = "-: CLEANED :-\n" + o.content;
}

The actual TinyMCE paste button only works with IE, but the ctrl-V shortcut works with every browser. However, the callback is not called.

I did some digging around. The paste_preprocess setting is definitely being added to the correct JavaScript object, but the only code that references it -- the TinyMCE Paste plugin -- isn't being loaded. So it looks like the problem is with Drupal, not TinyMCE.

Any help getting Drupal to load TinyMCE plugins correctly would be most appreciated.

1

1 Answers

1
votes

Make sure that the "paste" TinyMCE plugin is actually being loaded. For some reason, in Drupal there is an entry under "Buttons and Plugins" titled simply "Paste". This however does NOT enable the "paste" plugin required for the paste preprocess callback to occur.

Instead, make sure either "Paste Text" or "Paste from Word" is enabled. This should cause the "paste" plugin to load, and the paste preprocess callback to occur.