Removing the fieldset on a Drupal 7 date field

By shane
Wed, 2012-08-29 01:14

Share with Others

This is a relatively easy one, but I found myself scratching my head at this for longer than was necessary. There are times in which you do not want a Drupal 7 date field to be added inside a fieldset. One discussion on ( mentions applying a patch to the Date module. I think it is much better to just use the theme layer for it's intended purpose... overriding theme-able output. The main problem for a lot of people, is that they are just not as comfortable with PHP or are unsure which functions need to be overridden in your template.php to get the desired results.

So if you are looking for the simplest way to get your Drupal 7 date fields from displaying inside of a Fieldset, drop this code into your theme's template.php file (replacing MYTHEME with the name of your theme).

function MYTHEME_date_combo($variables) {
  return theme('form_element', $variables);

Just for reference, the original theme function was called theme_date_combo and is located in the date.theme file of the date module. Here is the original code:

function theme_date_combo($variables) {
  $element = $variables['element'];
  $field = field_info_field($element['#field_name']);
  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
  // Group start/end items together in fieldset.
  $fieldset = array(
    '#title' => t($element['#title']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
    '#value' => '',
    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
    '#attributes' => array(),
    '#children' => $element['#children'],
  return theme('fieldset', array('element' => $fieldset));

It is almost too simple... you just need to know which function to override.