public function ContentEntityBase::setNewRevision in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 264 - Contains \Drupal\Core\Entity\ContentEntityBase.
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);
// 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;
}