Jul 11, 2011 · Updated: Nov 04, 2017 · by Tim Kamanin
The task is very common, but in Drupal 7 you do this in a bit different way than in Drupal 6. Here's how to remove format options from comments textarea in Drupal 7: UPD: Well, the most easiest way to do this is to install Better Formats module (http://drupal.org/project/better_formats). But do we need another module installed to do this simple thing? Me, not, so let 's dig into the code a bit. Basically, we need to alter comment form.
You can do this in two ways:
It's up to you which way to choose. If you want your changes to be applicable not only to the active theme, then choose the second option. Ok, now, depending on a way you've chosen, add this code to your template.php or module_name.module file:
function ModulNameOrYourThemeName_form_comment_form_alter(&$form, &$form_state, &$form_id) {
$form['comment_body']['#after_build'][] = 'ModulNameOrYourThemeName_customize_comment_form';
}
Option A) If you only want to hide formatting guidelines and Filter Tips link , then add this function to the file:
function ModulNameOrYourThemeName_customize_comment_form(&$form) {
// Hide guideliness
$form[LANGUAGE_NONE][0]['format']['guidelines']['#access'] = FALSE; // Note 'und', you may need to set your comment form language code instead
// Hide Filter Tips
$form[LANGUAGE_NONE][0]['format']['help']['#access'] = FALSE;
return $form;
}
Option B) If you want to hide all format options , then add this function to the file:
function ModulNameOrYourThemeName_customize_comment_form(&$form) {
$form[LANGUAGE_NONE][0]['format']['#access'] = FALSE; // Note LANGUAGE_NONE, you may need to set your comment form language code instead
return $form;
}
Save your file and don 't forget to clear Drupal's cache (Configuration > Development > Performance > Clear All Caches).
That's all for now, enjoy and happy drupalling!
Hey, if you've found this useful, please share the post to help other folks find it: