summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-01-06 17:45:39 +1000
committerLee Rowlands2018-01-11 07:40:42 +1000
commit84785ee792c503209f6e6a28aee2491153c23985 (patch)
tree1005fd77476ecd09d0477a592e21e1d4396c0fdb
parent97bfb5624b46758eb91efa0b5ca47260bd8918ff (diff)
Issue #2934517 by Berdir: Setting a revision ID on a new entity sets the newRevision flag to false8.4.x
(cherry picked from commit 895db7dd8a9b83860cdf1f04686ea4c153665199)
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityBase.php2
-rw-r--r--core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php10
2 files changed, 11 insertions, 1 deletions
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 43db12f..04808a7 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -716,7 +716,7 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
// If the revision identifier field is being populated with the original
// value, we need to make sure the "new revision" flag is reset
// accordingly.
- if ($key === 'revision' && $this->getRevisionId() == $this->getLoadedRevisionId()) {
+ if ($key === 'revision' && $this->getRevisionId() == $this->getLoadedRevisionId() && !$this->isNew()) {
$this->newRevision = FALSE;
}
}
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php b/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php
index 601fac0..36a4852 100644
--- a/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php
@@ -203,6 +203,16 @@ class EntityRevisionsTest extends BrowserTestBase {
$this->assertNull($entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
$this->assertTrue($entity->isNewRevision());
+
+ // Check that calling setNewRevision() on a new entity without a revision ID
+ // and then with a revision ID does not unset the revision ID.
+ $entity = EntityTestMulRev::create(['name' => 'EntityLoadedRevisionTest']);
+ $entity->set('revision_id', NULL);
+ $entity->set('revision_id', 5);
+ $this->assertTrue($entity->isNewRevision());
+ $entity->setNewRevision();
+ $this->assertEquals(5, $entity->get('revision_id')->value);
+
}
}