I have added another content type called "Article". Now, I want to disable the wysiwyg api editor in the textarea of this content type.

Anyone know how to do this?

Comments

pixelite’s picture

When you're using the wysiwyg api, the wysiwyg is turned on or off depending on the input format. If you use it in conjunction with the Better Formats module (http://drupal.org/project/better_formats), there's a checkbox under input formats-> settings which allows you to fine tune which input format is the default for each node type. Then go to input formats -> defaults to choose input formats for each node type / user role combination.

jaypabs’s picture

Thanks for the module. I installed it but when I go to formats->defaults the role is applied for all nodes.

There's however a label in formats->defaults that says: These settings will be applied to all nodes and comments in the site unless overriden by specific content type defaults.

unless overridden by specific content type? Where can I override this?

WorldFallz’s picture

Directly from the README.txt file included with better_formats:

4. If you enable the "Control formats per node type" option. Go to your content
   type admin page to set those settings (example /admin/content/node-type/page).
   The settings are under the Input format settings fieldset.
jaypabs’s picture

Thank you very much. I am looking for the readme file before and mis-look it.

Thanks again.

Download free source code

revnoah’s picture

I needed to remove wysiwyg from the comments field. I already had a custom module set up with a form_alter function, so I modified that.

function my_module_form_alter($form_id, &$form) {
  if ($form_id['#id'] == 'comment-form') {
  	$form_id['comment_filter']['format'] = array();
  } 
}

I've posted more details and discussion on why I chose this method on my blog.

lizhenry’s picture

In a php file in my theme, I have a function for theme_comment_form to suppress some field titles from printing before their textareas. It looks something like this:


function theme_comment_form($form) {
$form['comment_filter']['format'] = array();
}

That seems to work okay so far.

intrafusion’s picture

There are a couple of minor errors in your code:

<?php
function my_module_form_alter($form_id, &$form) {
  if ($form_id['#id'] == 'comment_form') {
      $form['comment_filter']['format'] = array();
  } 
}
?>

comment-form should be comment_form and $form_id['comment_filter']['format'] = array(); should be $form['comment_filter']['format'] = array();

Drupal Jedi’s picture

Actually, revnoah's solution worked for me, whereas this one did not.

nvaken’s picture

I can not emphesize this good enough, but this hack might cause your comments to be highly sensitive to XSS (Cross-site scripting) since this hack removes formatting from your comment field. Especially for anonymous users, this content should be filtered against dangerous input like Javascript, HTML and any other possible dangers from entering your website.

I highly recommend using the better_formats module to fix this issue. Else, be at least sure enough that your formatting defaults are set correctly and filter malicious code.

I know this is an old topic, but for the sake of Googling people, this must be noted.

jaxxed’s picture

Ambidex is correct. Disabling the filters (filter.module) not only disables the wysiwyg but also the text filtering, which means that users can enter whatever they want, and can potentially open you up to user input attacks.

If your are using the wysiwyg module then you have another alternative:

First, here is a description of how wysiwyg gets the editor in place:

  1. wysiwyg does a form alter, which adds an '#after_build' to all forms. This means that when the drupal_build_form is finished collecting all of the form, and altering the form (hook_form_alter), the wysiwyg after_build function is run.
  2. The after_build processor processed the form from top to bottom, going through all children (element_children()) and checking for any element that has a 'filter' after it (this is actually not an exact science, but it works.) Any element that does have a filter, it processes for resizable and adds the editor initialization (one for each filter type as per the configuration.

OK now the magic:

In the wysiwyg.module after_build processor is the following code:

function wysiwyg_process_form( &$form ) (version as of today)
wysiwyg.module:134


          // Allow modules to programmatically enforce no client-side editor by
          // setting the #wysiwyg property to FALSE.
          if (isset($field['#wysiwyg']) && !$field['#wysiwyg']) {
            // A 'format' element should not have any child elements that may
            // need processing, so it should be safe to skip the recursion that
            // happens at the end of this function, and move on to the next
            // element on the same level.
            continue;
          }

This means that any element that would have an editor attached (the textareas) can have the wysiwyg editor disabled, if it has a #wysiwyg=false attribute in the form array.

That meaning that for the comment form, in any drupal module hook_form_alter, you can put this:

  // remove wysiwyg from comments
  if ( $form_id == 'comment_form' ) {
    $form['comment_filter']['comment']['#wysiwyg'] = false;
  }

Note that the if condition is for the form api version that I am using (I notice that some comments above are using a different formAPI.) All you really have to do is find your textarea, and add the #wysiwyg=false attribtue to it.

Note that this solution still allows filter selection as they were before the modification, and doesn't hide the format selector. You could technically hide that with CSS, and really you should modify filtering priveleges at role and node-type levels.

jaxxed’s picture

yareckon’s picture

So don't use the first snippet...

But you have to set the ['#wysiwyg'] = FALSE directly on whatever element is of type 'text_format', that is, a text area with textformats enabled. This means drilling down into the array, unfortunately..

This would work to eliminate wysiwyg on comment body in a hook_form_comment_form_alter for instance:

$lang_code = $form['comment_body']['#language'];
$form['comment_body'][$lang_code][0]['#wysiwyg'] = FALSE;  // 0 because comment_body is not a multiple field