public function ContentEntityBase::setNewRevision

public ContentEntityBase::setNewRevision($value = TRUE)

Enforces an entity to be saved as a new revision.

Parameters

bool $value: (optional) Whether a new revision should be saved.

Throws

\LogicException Thrown if the entity does not support revisions.

Overrides RevisionableInterface::setNewRevision

See also

\Drupal\Core\Entity\EntityInterface::isNewRevision()

File

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

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);

    // Make sure that the flag tracking which translations are affected by the
    // current revision is reset.
    foreach ($this->translations as $langcode => $data) {
      // But skip removed translations.
      if ($this->hasTranslation($langcode)) {
        $this->getTranslation($langcode)->setRevisionTranslationAffected(NULL);
      }
    }
  }

  $this->newRevision = $value;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityBase.php/function/ContentEntityBase::setNewRevision/8.1.x