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; }
Please login to continue.