contrib-jrockowitz/fieldset_helper/fieldset_helper.module, line 170
_fieldset_helper_set_collapsible_fieldset_ids(&$form, $form_id, $id='fieldset')Set collapsible fieldsets id based on the associated array keys.
All fieldset id's will begin with 'fieldset-' to insure their uniqueness.
&$form Nested array of form elements that comprise the form.
$form_id String representing the id of the form.
$id Based id for collapsible fieldsets.
TRUE if a form contains a collapsible fieldset.
<?php
function _fieldset_helper_set_collapsible_fieldset_ids(&$form, $form_id, $id='fieldset') {
static $has_collapsible_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);
// Handle collapsible fieldset.
if (isset($form[$key]['#collapsible']) && $form[$key]['#collapsible']) {
// Add id to the collapsible fieldset if an id is not defined.
if (!isset($form[$key]['#attributes']['id'])) {
$form[$key]['#attributes']['id'] = $fieldset_id;
}
// Set that this form has a collapsible fieldset.
$has_collapsible_fieldset[$form_id] = TRUE;
}
// Recurse downward
_fieldset_helper_set_collapsible_fieldset_ids($form[$key], $form_id, $fieldset_id);
}
// Return if the form has a collapsible fieldset.
return ( isset($has_collapsible_fieldset[$form_id]) && $has_collapsible_fieldset[$form_id]) ? TRUE : FALSE;
}
?>