Same name and namespace in other branches
- 6.x modules/node/content_types.inc \node_type_form_submit()
- 7.x modules/node/content_types.inc \node_type_form_submit()
Implementation of hook_form_submit().
File
- modules/
node/ content_types.inc, line 256 - Content type editing UI.
Code
function node_type_form_submit($form_id, $form_values) {
$op = isset($form_values['op']) ? $form_values['op'] : '';
$type = new stdClass();
$type->type = trim($form_values['type']);
$type->name = trim($form_values['name']);
$type->orig_type = trim($form_values['orig_type']);
$type->old_type = isset($form_values['old_type']) ? $form_values['old_type'] : $type->type;
$type->description = $form_values['description'];
$type->help = $form_values['help'];
$type->min_word_count = $form_values['min_word_count'];
$type->title_label = $form_values['title_label'];
$type->body_label = $form_values['body_label'];
// title_label is required in core; has_title will always be true, unless a
// module alters the title field.
$type->has_title = $type->title_label != '';
$type->has_body = $type->body_label != '';
$type->module = !empty($form_values['module']) ? $form_values['module'] : 'node';
$type->custom = $form_values['custom'];
$type->modified = TRUE;
$type->locked = $form_values['locked'];
if ($op == t('Reset to defaults')) {
node_type_reset($type);
}
elseif ($op == t('Delete content type')) {
return 'admin/content/types/' . str_replace('_', '-', $type->old_type) . '/delete';
}
$status = node_type_save($type);
$variables = $form_values;
// Remove everything that's been saved already - whatever's left is assumed
// to be a persistent variable.
foreach ($variables as $key => $value) {
if (isset($type->{$key})) {
unset($variables[$key]);
}
}
unset($variables['form_token'], $variables['op'], $variables['submit'], $variables['delete'], $variables['reset'], $variables['form_id']);
// Save or reset persistent variable values.
foreach ($variables as $key => $value) {
$key .= '_' . $type->type;
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
if (is_array($value)) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
if ($type->old_type != $type->type) {
$key = str_replace($type->type, $type->old_type, $key);
variable_del($key);
}
}
}
node_types_rebuild();
// menu_rebuild clears the cache, too
menu_rebuild();
$t_args = array(
'%name' => $type->name,
);
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The content type %name has been reset to its default values.', $t_args));
return;
}
if ($status == SAVED_UPDATED) {
drupal_set_message(t('The content type %name has been updated.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The content type %name has been added.', $t_args));
watchdog('node', t('Added content type %name.', $t_args), WATCHDOG_NOTICE, l(t('view'), 'admin/content/types'));
}
return 'admin/content/types';
}