function ContentEntityBase::setNewRevision

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::setNewRevision()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::setNewRevision()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::setNewRevision()

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 303

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function setNewRevision($value = TRUE) {
    if (!$this->getEntityType()
        ->hasKey('revision')) {
        throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions.");
    }
    if ($value && !$this->newRevision) {
        // When saving a new revision, set any existing revision ID to NULL so as
        // to ensure that a new revision will actually be created.
        $this->set($this->getEntityType()
            ->getKey('revision'), NULL);
    }
    elseif (!$value && $this->newRevision) {
        // If ::setNewRevision(FALSE) is called after ::setNewRevision(TRUE) we
        // have to restore the loaded revision ID.
        $this->set($this->getEntityType()
            ->getKey('revision'), $this->getLoadedRevisionId());
    }
    $this->newRevision = $value;
}

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