diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index c03266f..7c0c711 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -163,6 +163,13 @@ protected $validationRequired = FALSE; /** + * The original revision id before the new revision was set. + * + * @var int + */ + protected $originalRevisionId; + + /** * {@inheritdoc} */ public function __construct(array $values, $entity_type, $bundle = FALSE, $translations = array()) { @@ -266,7 +273,7 @@ public function setNewRevision($value = TRUE) { 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->original_revision = $this->getRevisionId(); + $this->originalRevisionId = $this->getRevisionId(); $this->set($this->getEntityType()->getKey('revision'), NULL); // Make sure that the flag tracking which translations are affected by the @@ -286,19 +293,23 @@ public function setNewRevision($value = TRUE) { * {@inheritdoc} */ public function getOriginalRevisionId() { - if (isset($this->original_revision)) { - return $this->original_revision; + $revison_id = $this->originalRevisionId; + if (!$revison_id) { + $revison_id = $this->getRevisionId(); } + return $revison_id; } /** * {@inheritdoc} */ public function loadUnchangedRevision() { - $storage = $this->entityTypeManager() - ->getStorage($this->entityTypeId); - $storage->resetCache([$this->id()]); - return $storage->loadRevision($this->getOriginalRevisionId()); + if ($this->getOriginalRevisionId()) { + $storage = $this->entityTypeManager() + ->getStorage($this->entityTypeId); + $storage->resetCache([$this->id()]); + return $storage->loadRevision($this->getOriginalRevisionId()); + } } /**