function _content_admin_field_add_existing_submit in Content Construction Kit (CCK) 5
Same name and namespace in other branches
- 6 includes/content.admin.inc \_content_admin_field_add_existing_submit()
Add an existing field to a content type.
File
- ./
content_admin.inc, line 576 - Administrative interface for content type creation.
Code
function _content_admin_field_add_existing_submit($form_id, $form_values) {
$type = content_types($form_values['type_name']);
$field = content_fields($form_values['field_name']);
$field_types = _content_field_types();
$field_type = $field_types[$field['type']];
$columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $field);
if (is_array($columns) && count($columns)) {
if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) {
$new_field = $field;
$new_field['db_storage'] = CONTENT_DB_STORAGE_PER_FIELD;
db_query("UPDATE {node_field} SET db_storage = %d WHERE field_name = '%s'", CONTENT_DB_STORAGE_PER_FIELD, $form_values['field_name']);
content_alter_db_field($field, $columns, $new_field, $columns);
}
}
$prior_instance = db_fetch_array(db_query("SELECT * FROM {node_field_instance} WHERE field_name = '%s'", $form_values['field_name']));
if (!$prior_instance) {
$prior_instance = array();
$prior_instance['weight'] = 0;
$prior_instance['label'] = $form_values['field_name'];
$prior_instance['widget_type'] = '';
$prior_instance['widget_settings'] = '';
$prior_instance['display_settings'] = '';
$prior_instance['description'] = '';
}
db_query("INSERT INTO {node_field_instance} (field_name, type_name, weight, label, widget_type, widget_settings, display_settings, description) VALUES ('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s')", $form_values['field_name'], $form_values['type_name'], $prior_instance['weight'], $prior_instance['label'], $prior_instance['widget_type'], $prior_instance['widget_settings'], $prior_instance['display_settings'], $prior_instance['description']);
drupal_set_message(t('Added field %label.', array(
'%label' => $prior_instance['label'],
)));
content_clear_type_cache();
return 'admin/content/types/' . $type['url_str'] . '/fields';
}