function _fieldgroup_add_group_to_form in Content Construction Kit (CCK) 6.3
1 call to _fieldgroup_add_group_to_form()
- fieldgroup_form_alter in modules/
fieldgroup/ fieldgroup.module - Implementation of hook_form_alter()
File
- modules/
fieldgroup/ fieldgroup.module, line 373 - Create field groups for CCK fields.
Code
function _fieldgroup_add_group_to_form(&$form, &$form_state, $form_id, $group_name, $group, $groups) {
$form[$group_name] = array(
'#type' => 'fieldset',
'#title' => check_plain(t($group['label'])),
'#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed',
'#collapsible' => in_array($group['settings']['form']['style'], array(
'fieldset_collapsed',
'fieldset_collapsible',
)),
'#weight' => $group['weight'],
'#depth' => $group['depth'],
'#group_parent' => $group['parent'],
'#description' => content_filter_xss(t($group['settings']['form']['description'])),
'#attributes' => array(
'class' => strtr($group['group_name'], '_', '-'),
),
);
$has_accessible_field = FALSE;
foreach ($group['fields'] as $field_name => $field) {
if (isset($form[$field_name])) {
$form[$field_name]['#weight'] = $field['weight'];
$form[$group_name][$field_name] = $form[$field_name];
//Track whether this group has any accessible fields within it.
if (!isset($form[$field_name]['#access']) || $form[$field_name]['#access'] !== FALSE) {
$has_accessible_field = TRUE;
}
unset($form[$field_name]);
}
}
if (!empty($group['fields']) && !element_children($form[$group_name])) {
//hide the fieldgroup, because the fields are hidden too
unset($form[$group_name]);
}
if (!$has_accessible_field) {
// Hide the fieldgroup, because the fields are inaccessible.
$form[$group_name]['#access'] = FALSE;
}
else {
//cascade visibility up
$form[$group_name]['#access'] = TRUE;
}
// Allow other modules to alter the form.
// Can't use module_invoke_all because we want
// to be able to use a reference to $form and $form_state.
foreach (module_implements('fieldgroup_form') as $module) {
$function = $module . '_fieldgroup_form';
$function($form, $form_state, $form_id, $group);
}
}