Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By r2b2 on
In TinyMCE, the advance style settings just injects span tags with the class name. Now what I would want is to make the classes specific to block elements, like H1,H2 and so on.. I don't know any other way to do it but this :
//after all the js files are loaded insert this in your page.tpl.php:
<script type='text/javascript'>
jQuery.extend(Drupal.settings.wysiwyg.configs.tinymce.format2 ,
{style_formats :
[
{title : 'Heading 1 - Green', block : 'h1', classes : 'goape-green'},
{title : 'Heading 2 - Orange', block : 'h1', classes : 'goape-orange'}
]
});
</script>
What this does is to extend the Drupal object and inject some additional settings. Now for any selected text and you applied this format it will automatically convert it to the appropriate element...
THanks
Comments
As long as WYSIWYG API is
As long as WYSIWYG API is rather limited in functionality, you could also put the following code in a custom.module:
-Stefan
Extending WYSIWYG
As long as you're tossing together a custom module to inject additional editor configuration information, it's quite easy to use Drupal's hook_form_FORM_ID_alter() functionality to add or modify (or even remove entirely) elements of WYSIWYG's configuration form. Once you've wandered this far afield, it's also quite easy to add your own function to either pre-process, post-process or completely replace WYSIWYG's form submit function. Article drupal.org/node/637500 talks about this.
For example, if you want to change the css_path entry element to a textarea instead of a textbox, the following code fragment will achieve that. The fragment also specifies an additional submit function that will be called. This fragment uses array_unshift to put the added submit function at the head of the array so it will be called first. Alternatively, array_push (or simply assigning to $form['#submit'][]) will add the new function to the end of the array so it will be called last. And a straight assignment to $form['#submit;] will replace WYSIWYG's form submit function - as well as any additional submit functions already in place - with one of your own devising.
Note that the calls to drupal_set_message() are simply for trace printing and should be omitted from the production version of the module.
Note also that hook_form_alter() can be used here, as long as you remember to test the value of the $form_id parameter to make sure you're hijacking the right form.
Having added or modified the saved WYSIWYG editor configuration, you may need to use the hook_wysiwyg_editor_settings_alter() hook shown earlier in this thread to actually pass your new configuration elements to the editor as it initialises.