Commit eb86c277 authored by mbovan's avatar mbovan Committed by miro_dietiker

Issue #2848029 by mbovan, chr.fritsch: Prevent duplicate revisions by checking...

Issue #2848029 by mbovan, chr.fritsch: Prevent duplicate revisions by checking whether a host entity is already saved
parent 676442fe
......@@ -259,7 +259,7 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
$host = $this->getEntity();
$needs_save = $this->entity instanceof EntityNeedsSaveInterface && $this->entity->needsSave();
if ($host->isNewRevision() && $this->entity && $this->entity->getEntityType()->get('entity_revision_parent_id_field')) {
if (!$host->isNew() && $host->isNewRevision() && $this->entity && $this->entity->getEntityType()->get('entity_revision_parent_id_field')) {
$this->entity->setNewRevision();
if ($host->isDefaultRevision()) {
$this->entity->isDefaultRevision(TRUE);
......
......@@ -78,6 +78,9 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
));
$composite->save();
// Assert that there is only 1 revision of the composite entity.
$composite_revisions_count = \Drupal::entityQuery('entity_test_composite')->condition('uuid', $composite->uuid())->allRevisions()->count()->execute();
$this->assertEquals(1, $composite_revisions_count);
// Create a node with a reference to the test composite entity.
$node = Node::create(array(
......@@ -90,6 +93,9 @@ class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {
// Assert that there is only 1 revision when creating a node.
$node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();
$this->assertEqual($node_revisions_count, 1);
// Assert there is no new composite revision after creating a host entity.
$composite_revisions_count = \Drupal::entityQuery('entity_test_composite')->condition('uuid', $composite->uuid())->allRevisions()->count()->execute();
$this->assertEquals(1, $composite_revisions_count);
// Verify the value of parent type and id after create a node.
$composite = EntityTestCompositeRelationship::load($composite->id());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment