function _content_admin_field_submit in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6 includes/content.admin.inc \_content_admin_field_submit()
Save a field's settings after editing.
File
- ./
content_admin.inc, line 1013 - Administrative interface for content type creation.
Code
function _content_admin_field_submit($form_id, $form_values) {
$type = content_types($form_values['type_name']);
$field = $type['fields'][$form_values['field_name']];
$field_types = _content_field_types();
$field_type = $field_types[$field['type']];
$widget_types = _content_widget_types();
$widget_type = $widget_types[$form_values['widget_type']];
// If content.module is handling the default value,
// initialize $widget_settings with default values,
if (content_handle('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) {
$widget_settings = array(
'default_value' => $form_values['default_value'],
'default_value_php' => $form_values['default_value_php'],
);
}
$setting_names = module_invoke($widget_type['module'], 'widget_settings', 'save', $field);
if (is_array($setting_names)) {
foreach ($setting_names as $setting) {
$widget_settings[$setting] = $form_values[$setting];
}
}
$field_settings = array();
$setting_names = module_invoke($field_type['module'], 'field_settings', 'save', $field);
if (is_array($setting_names)) {
foreach ($setting_names as $setting) {
$field_settings[$setting] = $form_values[$setting];
}
}
$prev_field = $field;
$prev_columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $field);
db_query("UPDATE {node_field_instance} SET weight = %d, label = '%s', widget_type = '%s', widget_settings = '%s', description = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['weight'], $form_values['label'], $form_values['widget_type'], serialize($widget_settings), $form_values['description'], $form_values['type_name'], $form_values['field_name']);
if ($form_values['multiple']) {
$field['db_storage'] = CONTENT_DB_STORAGE_PER_FIELD;
}
else {
$instances = db_result(db_query("SELECT COUNT(*) FROM {node_field_instance} WHERE field_name = '%s'", $form_values['field_name']));
if ($instances == 1) {
$field['db_storage'] = CONTENT_DB_STORAGE_PER_CONTENT_TYPE;
}
}
db_query("UPDATE {node_field} SET required = %d, multiple = %d, global_settings = '%s', db_storage = %d WHERE field_name = '%s'", $form_values['required'], $form_values['multiple'], serialize($field_settings), $field['db_storage'], $form_values['field_name']);
drupal_set_message(t('Saved field %field.', array(
'%field' => $form_values['label'],
)));
content_clear_type_cache();
$new_field = content_fields($form_values['field_name']);
$new_columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $new_field);
if (!isset($prev_columns)) {
$prev_columns = array();
}
if (!isset($new_columns)) {
$new_columns = array();
}
content_alter_db_field($prev_field, $prev_columns, $new_field, $new_columns);
return 'admin/content/types/' . $type['url_str'] . '/fields';
}