function Node::preSave

Same name and namespace in other branches
  1. 9 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::preSave()
  2. 8.9.x core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::preSave()
  3. 10 core/modules/node/src/Entity/Node.php \Drupal\node\Entity\Node::preSave()

Overrides ContentEntityBase::preSave

File

core/modules/node/src/Entity/Node.php, line 115

Class

Node
Defines the node entity class.

Namespace

Drupal\node\Entity

Code

public function preSave(EntityStorageInterface $storage) {
  parent::preSave($storage);
  foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
    $translation = $this->getTranslation($langcode);
    // If no owner has been set explicitly, make the anonymous user the owner.
    if (!$translation->getOwner()) {
      $translation->setOwnerId(0);
    }
  }
  // If no revision author has been set explicitly, make the node owner the
  // revision author.
  if (!$this->getRevisionUser()) {
    $this->setRevisionUserId($this->getOwnerId());
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.