public function ContentEntityBase::setNewRevision in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::setNewRevision()
- 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::setNewRevision()
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 291
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
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;
}