public function NodeFormController::save

Overrides Drupal\Core\Entity\EntityFormController::save().

Overrides EntityFormController::save

File

drupal/core/modules/node/lib/Drupal/node/NodeFormController.php, line 435
Definition of Drupal\node\NodeFormController.

Class

NodeFormController
Form controller for the node edit forms.

Namespace

Drupal\node

Code

public function save(array $form, array &$form_state) {
  $node = $this->entity;
  $insert = empty($node->nid);
  $node
    ->save();
  $node_link = l(t('view'), 'node/' . $node->nid);
  $watchdog_args = array(
    '@type' => $node->type,
    '%title' => $node
      ->label(),
  );
  $t_args = array(
    '@type' => node_get_type_label($node),
    '%title' => $node
      ->label(),
  );
  if ($insert) {
    watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been created.', $t_args));
  }
  else {
    watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
    drupal_set_message(t('@type %title has been updated.', $t_args));
  }
  if ($node->nid) {
    $form_state['values']['nid'] = $node->nid;
    $form_state['nid'] = $node->nid;
    $form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>';
  }
  else {

    // In the unlikely case something went wrong on save, the node will be
    // rebuilt and node form redisplayed the same way as in preview.
    drupal_set_message(t('The post could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }

  // Clear the page and block caches.
  cache_invalidate_tags(array(
    'content' => TRUE,
  ));
}