Score:0

Add custom buttons to TinyMCE editor toolbar

cn flag

I'm trying to add a custom button to my TinyMCE editor in Wysiwyg on a Drupal 7 install.

I've managed to adapt TinyMCE settings to work in my custom module, like so:

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'tinymce')
  if ($context['profile']->format == 'filtered_html') {
    $settings['browser_spellcheck'] = TRUE;
    $settings['toolbar'] = "bold italic underline mybutton";
}
}

TinyMCE recommends the following (source):

tinymce.init({
  selector: '#editor',
  toolbar: 'myCustomToolbarButton',
  setup: function (editor) {
    editor.ui.registry.addButton('myCustomToolbarButton', {
      text: 'My Custom Button',
      onAction: function () {
        alert('Button clicked!');
      }
    });
  }
});

I'm struggling with the "setup: function (editor)" part, which I can't seem to adapt correctly for either Jquery to add to my custom.js or to include in the MyModule code without breaking.

What is the best way to stitch this together? Does it wrap in a array setting? What's the correct syntax?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.