function node_type_form_submit
7.x content_types.inc | node_type_form_submit($form, &$form_state) |
6.x content_types.inc | node_type_form_submit($form, &$form_state) |
Implementation of hook_form_submit().
File
- drupal-6.x/
modules/ node/ content_types.inc, line 252 - Content type editing UI.
Code
function node_type_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
$type = new stdClass();
$type->type = trim($form_state['values']['type']);
$type->name = trim($form_state['values']['name']);
$type->orig_type = trim($form_state['values']['orig_type']);
$type->old_type = isset($form_state['values']['old_type']) ? $form_state['values']['old_type'] : $type->type;
$type->description = $form_state['values']['description'];
$type->help = $form_state['values']['help'];
$type->min_word_count = $form_state['values']['min_word_count'];
$type->title_label = $form_state['values']['title_label'];
$type->body_label = $form_state['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_state['values']['module']) ? $form_state['values']['module'] : 'node';
$type->custom = $form_state['values']['custom'];
$type->modified = TRUE;
$type->locked = $form_state['values']['locked'];
if ($op == t('Reset to defaults')) {
node_type_reset($type);
}
elseif ($op == t('Delete content type')) {
$form_state['redirect'] = 'admin/content/node-type/' . str_replace('_', '-', $type->old_type) . '/delete';
return;
}
$status = node_type_save($type);
$variables = $form_state['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) {
$variable_new = $key . '_' . $type->type;
$variable_old = $key . '_' . $type->old_type;
if ($op == t('Reset to defaults')) {
variable_del($variable_old);
}
else {
if (is_array($value)) {
$value = array_keys(array_filter($value));
}
variable_set($variable_new, $value);
if ($variable_new != $variable_old) {
variable_del($variable_old);
}
}
}
node_types_rebuild();
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', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/content/types'));
}
$form_state['redirect'] = 'admin/content/types';
return;
}