function content_field_overview_form_submit in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6.2 includes/content.admin.inc \content_field_overview_form_submit()
File
- includes/
content.admin.inc, line 497 - Administrative interface for content type creation.
Code
function content_field_overview_form_submit($form, &$form_state) {
$form_values = $form_state['values'];
$type_name = $form['#type_name'];
$type = content_types($type_name);
// Update field weights.
$extra = array();
foreach ($form_values as $key => $values) {
// Groups are handled in fieldgroup_content_overview_form_submit().
if (in_array($key, $form['#fields'])) {
db_query("UPDATE {" . content_instance_tablename() . "} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", $values['weight'], $type_name, $key);
}
elseif (in_array($key, $form['#extra'])) {
$extra[$key] = $values['weight'];
}
}
if ($extra) {
variable_set('content_extra_weights_' . $type_name, $extra);
}
else {
variable_del('content_extra_weights_' . $type_name);
}
content_clear_type_cache();
$destinations = array();
// Create new field.
if (!empty($form_values['_add_new_field']['field_name'])) {
$field = $form_values['_add_new_field'];
$field['type_name'] = $type_name;
module_load_include('inc', 'content', 'includes/content.crud');
if (content_field_instance_create($field)) {
// Store new field information for fieldgroup submit handler.
$form_state['fields_added']['_add_new_field'] = $field['field_name'];
$destinations[] = 'admin/content/node-type/' . $type['url_str'] . '/fields/' . $field['field_name'];
}
else {
drupal_set_message(t('There was a problem creating field %label.', array(
'%label' => $field['label'],
)));
}
}
// Add existing field.
if (!empty($form_values['_add_existing_field']['field_name'])) {
$field = $form_values['_add_existing_field'];
$field['type_name'] = $type_name;
$existing_field = content_fields($field['field_name']);
if ($existing_field['locked']) {
drupal_set_message(t('The field %label cannot be added to a content type because it is locked.', array(
'%label' => $field['field_name'],
)));
}
else {
module_load_include('inc', 'content', 'includes/content.crud');
if (content_field_instance_create($field)) {
// Store new field information for fieldgroup submit handler.
$form_state['fields_added']['_add_existing_field'] = $field['field_name'];
$destinations[] = 'admin/content/node-type/' . $type['url_str'] . '/fields/' . $field['field_name'];
}
else {
drupal_set_message(t('There was a problem adding field %label.', array(
'%label' => $field['field_name'],
)));
}
}
}
if ($destinations) {
$destinations[] = urldecode(substr(drupal_get_destination(), 12));
unset($_REQUEST['destination']);
$form_state['redirect'] = content_get_destinations($destinations);
}
}