function fieldset_helper_form_alter in Fieldset helper 6
Same name and namespace in other branches
- 6.2 fieldset_helper.module \fieldset_helper_form_alter()
Implementation of hook_form_alter().
File
- ./
fieldset_helper.module, line 97 - Saves the collapsed state of a Drupal collapsible fieldset.
Code
function fieldset_helper_form_alter(&$form, $form_state, $form_id) {
// Check if user can save fieldset state
// and confirm that the form is not the test form.
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 variable.
$form_id = isset($form['#id']) ? $form['#id'] : $form_id;
// Check the auto_exclude list of forms that do not have collapsible fieldset.
// 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();
}
}