Friday 2 December 2011

Drupal 6: Enable/Disable the WYSIWYG Editor on Specific Forms

You will need your own custom module for this, in order to implement hook_form_FORM_ID_alter().

DISABLING
You can disable the WYSIWYG editor on any form by setting the FAPI (Forms API) setting #wysiwyg to FALSE e.g. for the Page node edit form, you can do this:
function MODULE_form_page_node_form_alter(&$form, &$form_state) {
    $form['body_field']['body']['#wysiwyg'] = FALSE;
}

ENABLING
  1. Some contrib modules (e.g. Ubercart) have completely disabled WYSIWYG editors on some of their textareas, and I haven't found a way around this.
  2. If you have checked the "Enable by default" option, the WYSIWYG editor should automatically be enabled for any form fields that have the "Input format" option below them.
  3. For other forms (with simple textareas that dont have the "Input format" option) you must manually enable the "Input format" option yourself. This can be done by again altering the $form object in your hook_form_FORM_ID_alter() e.g. for the Description field on the form to edit a content type:
function MODULE_form_node_type_form_alter(&$form, &$form_state) {
    $form['identity']['format'] = filter_form();
}


Update: if you're more into GUIs than fiddling in the code, you could just install the Better Formats module, which gives you loads of control on which Input formats are used for which forms. Then by having one plain-text input format, and another one associated with a WYSIWYG editor, you can easily control which forms use which.

3 comments:

  1. In D7, for a book page; use hook_form_book_node_form_alter and
    $form['body'][''][0]['#wysiwyg'] = FALSE

    ReplyDelete
  2. dude guy bro man5 January 2012 at 23:28

    How about for something in a node object?
      $form['#node']->field_award_teaser[0]['format']['#access'] = FALSE;

    ^^doesn't work.  I don't see the '#access' bit there so that's probably why.  What am I missing?
    Thanks.

    ReplyDelete
  3. Drupal 7 Try: $form['body'][LANGUAGE_NONE][0]['#wysiwyg'] = FALSE;

    ReplyDelete