function _fieldset_helper_set_fieldset_ids_recursive in Fieldset helper 6.2
Recursively set a fieldset ids based on the associated array keys.
All fieldset id's will begin with 'fieldset-' to insure their uniqueness.
Parameters
&$form: Nested array of form elements that comprise the form.
$form_id: String representing the id of the form.
$id: Based id for fieldsets.
1 call to _fieldset_helper_set_fieldset_ids_recursive()
- fieldset_helper_form_alter in ./
fieldset_helper.module - Implementation of hook_form_alter().
File
- ./
fieldset_helper.module, line 136
Code
function _fieldset_helper_set_fieldset_ids_recursive(&$form, $form_id, $id = 'fieldset') {
foreach ($form as $key => $value) {
// If $key is a property (begins with a hash (#) then continue.
if (strpos($key, '#') === 0) {
continue;
}
// If this element has no type or it is not a fieldset then continue.
if (!isset($form[$key]['#type']) || $form[$key]['#type'] != 'fieldset') {
continue;
}
// Add key, as valid DOM id, to fieldset id.
$fieldset_id = _fieldset_helper_format_id($id . '-' . $key);
// Add id to the collapsible fieldset if an id is not defined.
if (!isset($form[$key]['#attributes']['id'])) {
$form[$key]['#attributes']['id'] = $fieldset_id;
}
// Recurse downward
_fieldset_helper_set_fieldset_ids_recursive($form[$key], $form_id, $fieldset_id);
}
}