function fieldgroup_form_alter in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 5 fieldgroup.module \fieldgroup_form_alter()
- 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
- 6.2 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
File
- modules/
fieldgroup/ fieldgroup.module, line 302 - Create field groups for CCK fields.
Code
function fieldgroup_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) {
$form[$group_name] = array(
'#type' => 'fieldset',
'#title' => 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'],
'#description' => 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[$group_name][$field_name] = $form[$field_name];
// Track whether this group has any accessible fields within it.
if ($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;
}
}
}
elseif ($form_id == '_content_admin_field') {
$content_type = content_types($form['type_name']['#value']);
$form['widget']['group'] = array(
'#type' => 'select',
'#title' => t('Display in group'),
'#options' => _fieldgroup_groups_label($content_type['type']),
'#default_value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']),
'#description' => t('Select a group, in which the field will be displayed on the editing form.'),
'#weight' => 5,
);
$form['widget']['weight']['#weight'] = 5;
$form['widget']['description']['#weight'] = 7;
$form['#submit'][] = 'fieldgroup_content_admin_form_submit';
}
elseif ($form_id == 'content_admin_field_overview_form' && !empty($form['#groups'])) {
$form['#submit'][] = 'fieldgroup_content_overview_form_submit';
}
elseif ($form_id == 'content_admin_display_overview_form' && !empty($form['#groups'])) {
$form['#submit'][] = 'fieldgroup_display_overview_form_submit';
if (!isset($form['submit'])) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 10,
);
}
}
elseif ($form_id == '_content_admin_field_remove') {
$form['#submit'][] = 'fieldgroup_content_admin_field_remove_submit';
}
}