avocado shake (dot) net

WYSIWYG

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:

  1. Look in your modules/tinymce/tinymce.module file.
  2. Search for "theme_tinymce_theme".
  3. Copy the entire function to your theme's template.php file.
  4. Rename the function from theme_tinymce_theme() to yourthemename_tinymce_theme(). (Substitute "yourthemename" for your theme's name.)
  5. 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".

Avocado Shake (dot net) is the personal website of Gregory Go, co-founder of Killer Aces Media and Drupal fanboy.

Full text blog feed

My Tumblog

FriendFeed Stream

Essential Skills of a Community Manager
From Google Reader, posted Saturday, July 26, 2008 - 21:12.
Cartoon: Fannie Mae & Freddie Mac
From Mixx, posted Saturday, July 26, 2008 - 21:04.
Essential Skills of a Community Manager
From Google Reader, posted Saturday, July 26, 2008 - 20:24.
Picturing Casualties In Iraq: Slide Show
From Mixx, posted Saturday, July 26, 2008 - 20:20.
Submitted: 19 Tips for Cheering Yourself Up -- From 200 Years Ago
From Mixx, posted Saturday, July 26, 2008 - 20:03.
Submitted: 3 Tips for Losing Weight on a Budget
From Mixx, posted Saturday, July 26, 2008 - 19:50.
Submitted: How to Deal with a Partner That Hides Money Problems
From Mixx, posted Saturday, July 26, 2008 - 18:10.
Blogging's Glass Ceiling (Kara Jesella/New York Times)
From Google Reader, posted Saturday, July 26, 2008 - 18:02.
How to increase submit speed from 45s to a fraction while keeping Akismet anti-spam - Pligg Forum
From del.icio.us, posted Saturday, July 26, 2008 - 17:26.
Lazy Linux: 10 essential tricks for admins
From del.icio.us, posted Saturday, July 26, 2008 - 16:21.