technonaturalist

image link to hive image link to ko-fi

comment form

Drupal 7 notes: unsetting formatting tips

Following on from hiding unwanted elements in comment forms, I found this tip on one of the many threads in Drupal of people trying to hide the pesky formatting guidelines and came up with:

template.php

<?php
  function [theme_name]_form_comment_form_alter(&$form, &$form_state, $form_id)
  {
    $form['comment_body']['#after_build'][] = 'remove_tips';
  }
  
  function remove_tips(&$form)
  {
    unset($form['und'][0]['format']['guidelines']);
    unset($form['und'][0]['format']['help']);
    return $form;
  }
?>

That gets rid of everything but the fieldset container and for the roles that can use multiple text formats, the select box (the “Text format” label can be easily removed with $form['und'][0]['format']['format']['#title'] = ''; in the comment_form_alter).

Drupal 7 notes hiding unwanted form elements comment forms

Just so I don’t drive myself completely insane again.

It’s a fairly standard theming problem, you have your Drupal comment form rendering thusly:

Drupal comment form (in WANLN theme)

Your site is set to not allow posting by anonymous users, rendering the “Your name” field superfluous and you think the subject line looks ugly, is unnecessary or you just don’t want users giving their comments subjects for whatever reason.