fieldset_helper_form_alter

contrib-jrockowitz/fieldset_helper/fieldset_helper.module, line 102

Versions
6
fieldset_helper_form_alter(&$form, $form_state, $form_id)

Implementation of hook_form_alter().

Code

<?php
function fieldset_helper_form_alter(&$form, $form_state, $form_id) {
  // Check if user can save fieldset state and the form is not the test form,
  // which appears for everyone who know the URL.
  if ( !user_access('save fieldset state') && $form_id != 'fieldset_helper_test') {
    return;
  }

  // If the $form object has an id, which will be used in the <form> tag,
  // then replace the $form_id.
  $form_id = (isset($form['#id'])) ? $form['#id'] : $form_id;

  // Get list of forms that do not have collapsible fieldset and should be skipped.
  // This insures that all the below recursive code is only executed on forms that
  // have collapsible fieldsets.
  $auto_exclude = variable_get('fieldset_helper_auto_exclude', array());
  if (array_key_exists($form_id, $auto_exclude)) {
    return;
  }

  // Set collapsible fieldset ids and get a boolean for whether the form had collapsible fieldsets.
  $has_collapsible_fieldset = _fieldset_helper_set_collapsible_fieldset_ids($form, $form_id);

  // If the form does not have a collapsible fieldset then save this information
  // so that we know not to bother recursing this form in the future.
  if (!$has_collapsible_fieldset) {
    $auto_exclude[$form_id] = 1;
    ksort($auto_exclude);
    variable_set('fieldset_helper_auto_exclude', $auto_exclude);
  }
  else {
    // Add js
    _fieldset_helper_add_js();
  }
}
?>