1 node.types.inc | node_type_form_submit($form, &$form_state) |
Form submission handler for node_type_form().
See also
File
- core/
modules/ node/ node.types.inc, line 586 - Content type editing user interface.
Code
function node_type_form_submit($form, &$form_state) {
$type = $form['#node_type'];
$type->type = $form_state['values']['type'];
$type->name = trim($form_state['values']['name']);
$type->old_type = isset($form_state['values']['old_type']) ? $form_state['values']['old_type'] : $type->type;
$type->description = $form_state['values']['description'];
$type->node_preview = $form_state['values']['node_preview'];
$type->help = $form_state['values']['help'];
$type->title_label = $form_state['values']['title_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->modified = TRUE;
// Check for any keys that match those provided by hook_node_type_load(). Any
// values that match a settings key are saved automatically.
foreach ($form_state['values'] as $key => $value) {
if (array_key_exists($key, $type->settings)) {
$type->settings[$key] = $value;
}
}
$status = node_type_save($type);
menu_rebuild();
if ($status == SAVED_UPDATED) {
// Update node type permissions
foreach ($form_state['values']['roles'] as $role_name => $role) {
user_role_change_permissions($role->name, $form_state['values'][$role->name]);
}
backdrop_set_message(t('The content type %name has been updated.', array('%name' => $type->name)));
}
elseif ($status == SAVED_NEW) {
// Save new permissions
foreach ($form_state['values']['roles'] as $role_name => $role) {
$valid_perms = array();
// Re-create the permissions string in the format 'create $type content'
// from the default 'create content' for saving permissions.
foreach ($form_state['values'][$role->name] as $string => $perm) {
if ($perm) {
$parts = explode('content', $string);
$valid_string = $parts[0] . $type->type . ' content';
$valid_perms[] = $valid_string;
}
}
user_role_grant_permissions($role->name, $valid_perms);
}
if ($form_state['values']['body']) {
node_add_body_field($type);
}
backdrop_set_message(t('The content type %name has been added.', array('%name' => $type->name)));
watchdog('node', 'Added content type %name.', array('%name' => $type->name), WATCHDOG_NOTICE, l(t('view'), 'admin/structure/types'));
}
// Make the new content type indexable by default if Search module is enabled.
if (module_exists('search')) {
$search_content_types = config_get('search.settings', 'content_types');
// If no types are specified, then all types are enabled and there's no need
// to make any changes.
if ($search_content_types) {
$search_content_types[] = $type->type;
natsort($search_content_types);
config_set('search.settings', 'content_types', $search_content_types);
}
}
$form_state['redirect'] = 'admin/structure/types';
return;
}