You are here

function fieldset_helper_alter_theme_fieldset in Fieldset helper 6.2

Same name and namespace in other branches
  1. 6 fieldset_helper.module \fieldset_helper_alter_theme_fieldset()

Alters a fieldset element to set default attributes, state, and id.

Parameters

&$element: A FAPI fieldset element.

4 calls to fieldset_helper_alter_theme_fieldset()
fieldset_helper_fieldgroup_fieldset_custom_preprocess in ./fieldset_helper.theme.inc
Implementation of hook_theme_custom_preprocess().
fieldset_helper_fieldset_custom_preprocess in ./fieldset_helper.theme.inc
Implementation of hook_theme_custom_preprocess().
fieldset_helper_preprocess_fieldgroup in ./fieldset_helper.theme.inc
Implementation of hook_preprocess_fieldgroup().
fieldset_helper_preprocess_fieldset in ./fieldset_helper.theme.inc
Implementation of hook_preprocess_fieldset().

File

./fieldset_helper.theme.inc, line 148
Theme functions for fieldset helper module

Code

function fieldset_helper_alter_theme_fieldset(&$element) {

  // Make sure each fieldset element is only altered once.
  if (isset($element['#fieldset_helper_processed'])) {
    return;
  }

  // Don't set collapsible or collapsed classes for fieldsets that are missing
  // a <legend> (aka #title).
  if (empty($form_element['#title'])) {
    return;
  }

  // Set id for fieldsets without them.
  if (empty($element['#attributes']['id'])) {
    if (isset($element['#attributes']['class']) && preg_match('/group-[-_a-zA-Z]+/', $element['#attributes']['class'], $matches)) {
      $element['#attributes']['id'] = _fieldset_helper_format_id('fieldset-' . $matches[0]);
    }
    else {
      $element['#attributes']['id'] = _fieldset_helper_format_id('fieldset-' . $element['#title']);
    }
  }

  // If fieldset has no classes, add its id as a class.
  // This is extremely useful for styling input format fieldsets.
  if (empty($element['#attributes']['class'])) {

    // Remove form_clean_id incrementing for id.
    $class_name = preg_replace('/-\\d+$/', '', $element['#attributes']['id']);
    $element['#attributes']['class'] = $class_name;
  }

  // See if all fieldset are collapsible.
  if ($default_collapsible = fieldset_helper_default_collapsible()) {
    $element['#collapsible'] = $default_collapsible;
  }

  // Set fieldset's default collapsed state
  $element['#collapsed'] = isset($element['#collapsed']) ? $element['#collapsed'] : FALSE;
  if ($default_collapsed = fieldset_helper_default_collapsed()) {
    $element['#collapsed'] = $default_collapsed;
  }

  // Set fieldset state
  if (user_access('save fieldset state')) {
    $element['#collapsed'] = fieldset_helper_state_manager_get_state($element['#attributes']['id'], $element['#collapsed']);
  }

  // Alter fieldset element.
  drupal_alter('fieldset', $element);
  $element['#fieldset_helper_processed'] = TRUE;
}