function fieldgroup_field_overview_form_submit in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 6.3 modules/fieldgroup/fieldgroup.module \fieldgroup_field_overview_form_submit()
1 string reference to 'fieldgroup_field_overview_form_submit'
- fieldgroup_form_alter in modules/
fieldgroup/ fieldgroup.module - Implementation of hook_form_alter()
File
- modules/
fieldgroup/ fieldgroup.module, line 450 - Create field groups for CCK fields.
Code
function fieldgroup_field_overview_form_submit($form, &$form_state) {
$form_values = $form_state['values'];
$type_name = $form['#type_name'];
// Create new group if needed.
if (!empty($form_values['_add_new_group']['label'])) {
$group = $form_values['_add_new_group'];
$group['settings'] = field_group_default_settings($group['group_type']);
fieldgroup_save_group($type_name, $group);
$new_group_name = $group['group_name'];
}
// Parse incoming rows.
$add_field_rows = array(
'_add_new_field',
'_add_existing_field',
);
$field_rows = array_merge($form['#fields'], $add_field_rows);
foreach ($form_values as $key => $values) {
// If 'field' row: update field parenting.
if (in_array($key, $field_rows)) {
// If newly added fields were added to a group:
if (in_array($key, $add_field_rows)) {
// We replace the '_add_*_field' key with the actual name of
// the field that got added.
// content_field_overview_form_submit() placed those
// in $form_state['fields_added'] for us.
if (isset($form_state['fields_added'][$key])) {
$key = $form_state['fields_added'][$key];
}
else {
// No field was actually created : skip to next row.
continue;
}
}
// If the field was added to the newly created group, replace the
// '_add_new_group' value with the actual name of the group.
$parent = $values['parent'] == '_add_new_group' && isset($new_group_name) ? $new_group_name : $values['parent'];
// TODO: check the parent group does exist ?
fieldgroup_update_fields(array(
'field_name' => $key,
'group' => $parent,
'type_name' => $type_name,
));
}
elseif (in_array($key, $form['#groups'])) {
db_query("UPDATE {" . fieldgroup_tablename() . "} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'", $values['weight'], $type_name, $key);
}
}
cache_clear_all('fieldgroup_data:', content_cache_tablename(), TRUE);
}