function node_submit

Prepares a node for saving by populating the author and creation date.

Parameters

\Drupal\Core\Entity\EntityInterface $node: A node object.

Return value

Drupal\node\Node An updated node object.

2 calls to node_submit()
NodeFormController::submit in drupal/core/modules/node/lib/Drupal/node/NodeFormController.php
Updates the node object by processing the submitted values.
NodeSaveTest::testImport in drupal/core/modules/node/lib/Drupal/node/Tests/NodeSaveTest.php
Checks whether custom node IDs are saved properly during an import operation.

File

drupal/core/modules/node/node.module, line 961
The core module that allows content to be submitted to the site.

Code

function node_submit(EntityInterface $node) {
  global $user;

  // A user might assign the node author by entering a user name in the node
  // form, which we then need to translate to a user ID.
  if (isset($node->name)) {
    if ($account = user_load_by_name($node->name)) {
      $node->uid = $account->uid;
    }
    else {
      $node->uid = 0;
    }
  }

  // If a new revision is created, save the current user as revision author.
  if ($node
    ->isNewRevision()) {
    $node->revision_uid = $user->uid;
    $node->revision_timestamp = REQUEST_TIME;
  }
  $node->created = !empty($node->date) && $node->date instanceof DrupalDateTime ? $node->date
    ->getTimestamp() : REQUEST_TIME;
  $node->validated = TRUE;
  return $node;
}