form_process_fieldset
- Versions
- 7
form_process_fieldset(&$element, &$form_state)
Adds fieldsets to the specified group or adds group members to this fieldset.
Parameters
$element An associative array containing the properties and children of the fieldset.
$form_state The $form_state array for the form this fieldset belongs to.
Return value
The processed element.
Related topics
Code
includes/form.inc, line 2426
<?php
function form_process_fieldset(&$element, &$form_state) {
$parents = implode('][', $element['#parents']);
// Add this fieldset to a group if one is set and if it's not being
// added to itself.
if (isset($element['#group']) && $element['#group'] != $parents) {
if (isset($form_state['groups'][$element['#group']]) && !empty($form_state['groups'][$element['#group']]['#group_exists'])) {
// Trick drupal_render() into believing this has already been output.
// The group widget will rerender this later. This only happens when the
// group is actually defined ('#group_exists' is TRUE). This prevents
// fieldsets from disappearing when the group they are associated to
// does not exist.
// If the group does not exist yet, the element's #printed value is left
// as is. As soon as the group is processed (fieldsets are also groups;
// see below), this element's #printed value is set to TRUE to prevent
// rendering in the original context.
$element['#printed'] = TRUE;
}
// Store a reference to this fieldset for the vertical tabs processing
// function.
$form_state['groups'][$element['#group']][] = &$element;
}
// Each fieldset can be a group itself and gets a reference to all
// elements in its group.
$form_state['groups'][$parents]['#group_exists'] = TRUE;
// There might already be elements associated with this group. Since the
// group did not exist yet at the time they were added to this group, they
// couldn't set #printed to TRUE (see above). We now know that this group
// does in fact exist and set #printed to TRUE to prevent rendering in the
// original context.
foreach (element_children($form_state['groups'][$parents]) as $key) {
$form_state['groups'][$parents][$key]['#printed'] = TRUE;
}
$element['#group_members'] = &$form_state['groups'][$parents];
// Contains form element summary functionalities.
$element['#attached']['js']['misc/form.js'] = array('weight' => JS_LIBRARY + 1);
// Collapsible fieldsets
if (!empty($element['#collapsible'])) {
$element['#attached']['js'][] = 'misc/collapse.js';
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = array();
}
$element['#attributes']['class'][] = 'collapsible';
if (!empty($element['#collapsed'])) {
$element['#attributes']['class'][] = 'collapsed';
}
}
$element['#attributes']['id'] = $element['#id'];
return $element;
}
?>Login or register to post comments 