How to disable TinyMCE per fields in Drupal
There is a theme() function in the Drupal tinymce module that lets you (the admin/webmaster) turn off the rich text editor on a field by field basis.
Basic steps to disable TinyMCE in a specific Drupal form field:
- Look in your modules/tinymce/tinymce.module file.
- Search for "theme_tinymce_theme".
- Copy the entire function to your theme's template.php file.
- Rename the function from theme_tinymce_theme() to yourthemename_tinymce_theme(). (Substitute "yourthemename" for your theme's name.)
- Add a line to the switch($textarea_name){} block that specifies the name of the textarea you would like to exclude. Use the existing examples as a guide.
I wanted to disable the RTE for a custom plain text field in the node edit form. The field's name is "field-teaser-0-value". This is the line I added (marked with "KA") with some surrounding logic: (The fully modified theme that I put into my template.php is at the end of the post.)
function theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
switch ($textarea_name) {
case 'field-teaser-0-value': // KA: blog teaser (we want plain text only)
unset($init);
break;
}
}
To find the name of the field in question, load the form in your browser. Check the source code. Look for the name="" attribute for your field. That's the string you insert into the theme function.
Tip! For CCK (content) fields where the name is something like "field_teaser[0][value]", you need to replace the non-alphanumeric characters with a dash. So the $textarea_name variable for this field is actually written as "field-teaser-0-value".
Here's the final customized theme function I placed in my theme's template.php file. My theme is called "avocadoshake" and my comments are marked with a "KA".
Full text blog feed