function fieldgroup_form_alter in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 5 fieldgroup.module \fieldgroup_form_alter()
- 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
- 6 modules/fieldgroup/fieldgroup.module \fieldgroup_form_alter()
Implementation of hook_form_alter()
File
- modules/
fieldgroup/ fieldgroup.module, line 298 - 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' => 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'],
'#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[$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;
}
// 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);
}
}
}
elseif ($form_id == 'content_field_edit_form' && isset($form['widget'])) {
$content_type = content_types($form['type_name']['#value']);
$form['widget']['group'] = array(
'#type' => 'value',
'#value' => _fieldgroup_field_get_group($content_type['type'], $form['field_name']['#value']),
);
}
elseif ($form_id == 'content_field_overview_form') {
$form['#validate'][] = 'fieldgroup_field_overview_form_validate';
$form['#submit'][] = 'fieldgroup_field_overview_form_submit';
}
elseif ($form_id == 'content_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_field_remove_form') {
$form['#submit'][] = 'fieldgroup_field_remove_form_submit';
}
}