1 node.pages.inc node_form_submit($form, &$form_state)

Form submission handler that saves the node for node_form().

See also

node_form_validate()

node_form_submit_build_node()

File

core/modules/node/node.pages.inc, line 522
Callbacks for adding, editing, and deleting content and managing revisions.

Code

function node_form_submit($form, &$form_state) {
  $original_status = $form_state['node']->status && $form_state['node']->nid;
  $node = node_form_submit_build_node($form, $form_state);
  $insert = empty($node->nid);
  $node->save();
  $node_link = l(t('view'), 'node/' . $node->nid);
  $type = node_type_get_name($node);
  $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
  $t_args = array('@type' => $type, '%title' => $node->title, '@scheduled' => format_date($node->scheduled), '@interval' => format_interval($node->scheduled - REQUEST_TIME));
  $message = '';

  if ($node->scheduled) {
    if (!empty($original_status)) {
      $message = t('@type has been unpublished. It is scheduled to be republished on @scheduled (@interval from now).', $t_args);
    }
    else {
      $message = t('@type will be published on @scheduled (@interval from now).', $t_args);
    }
  }
  if ($insert) {
    watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    $message = $message ? $message : t('@type %title has been created.', $t_args);
  }
  else {
    watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    $message = $message ? $message : t('@type %title has been updated.', $t_args);
  }
  backdrop_set_message($message);

  if ($node->nid) {
    $form_state['values']['nid'] = $node->nid;
    $form_state['nid'] = $node->nid;

    // Determine whether to redirect user to full page display.
    $form_state['redirect'] = '<front>';
    if (node_access('view', $node)) {
      $form_state['redirect'] = 'node/' . $node->nid;

      // If node type set to prevent direct viewing of full page URL
      // stay on edit page if user is not permitted.
      $type = node_type_get_type($node);
      $bypass_hidden_path = user_access('view hidden paths');
      if ($type->settings['hidden_path'] && !$bypass_hidden_path) {
        $form_state['redirect'] = 'node/' . $node->nid . '/edit';
      }
    }
  }
  else {
    // In the unlikely case something went wrong on save, the node will be
    // rebuilt and node form redisplayed.
    backdrop_set_message(t('The content could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
}