diff -u b/src/EntityReferenceRevisionsItem.php b/src/EntityReferenceRevisionsItem.php --- b/src/EntityReferenceRevisionsItem.php +++ b/src/EntityReferenceRevisionsItem.php @@ -2,6 +2,7 @@ namespace Drupal\multiversion; +use Drupal\entity_reference_revisions\EntityNeedsSaveInterface; use Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem as ContribEntityReferenceRevisionsItem; /** @@ -17,7 +18,7 @@ * Change the logic around saving auto-created entities. * * @see \Drupal\multiversion\EntityReferenceFieldTrait::preSave() - * @see \Drupal\entity_reference_revisions\Plaugin\Field\FieldType\EntityReferenceRevisionsItem::preSave() + * @see \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::preSave() */ public function preSave() { $has_new = $this->hasNewEntity(); @@ -54,15 +55,14 @@ * process only after this method call. * * @see \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::postSave() - * @see \Drupal\multiversion\Drupal\multiversion\Entity\Storage\ContentEntityStorageTrait::saveWithoutForcingNewRevision() + * @see \Drupal\multiversion\Entity\Storage\ContentEntityStorageTrait::saveWithoutForcingNewRevision() */ public function postSave($update) { $needs_save = FALSE; // If any of entity, parent type or parent id is missing then return. - if (!$this->entity || !$this->entity->getEntityType() - ->get('entity_revision_parent_type_field') || !$this->entity->getEntityType() - ->get('entity_revision_parent_id_field') - ) { + if (!$this->entity + || !$this->entity->getEntityType()->get('entity_revision_parent_type_field') + || !$this->entity->getEntityType()->get('entity_revision_parent_id_field')) { return; } diff -u b/tests/src/Kernel/ParagraphsTest.php b/tests/src/Kernel/ParagraphsTest.php --- b/tests/src/Kernel/ParagraphsTest.php +++ b/tests/src/Kernel/ParagraphsTest.php @@ -84,6 +84,10 @@ ]); $node->save(); + // Assert that the default revision has been set correctly. + $entity = $this->nodeStorage->load(1); + $this->assertEquals(1, $entity->getRevisionId(), 'Default revision has been set correctly.'); + $node_revision_id = $node->getRevisionId(); $paragraph_entity_id = $node->field_paragraph->target_id; $paragraph_entity = $this->paragraphStorage->load($paragraph_entity_id); @@ -94,6 +98,11 @@ $paragraph->field_test_field = 'Second revision title'; $node->field_paragraph = $paragraph; $node->save(); + + // Assert that the default revision has been set correctly. + $entity = $this->nodeStorage->load(1); + $this->assertEquals(2, $entity->getRevisionId(), 'Default revision has been set correctly.'); + $paragraph_entity_revision_id = $node->field_paragraph->target_revision_id; $paragraph_entity = $this->paragraphStorage->loadRevision($paragraph_entity_revision_id); @@ -104,6 +113,13 @@ $paragraph_entity_revision_id = $node_first_revision->field_paragraph->target_revision_id; $paragraph_entity = $this->paragraphStorage->loadRevision($paragraph_entity_revision_id); $this->assertEquals($paragraph_entity->field_test_field->value, 'First revision title'); + + // One more time, test if node default revision is set correctly. + $node->save(); + + // Assert that the default revision has been set correctly. + $entity = $this->nodeStorage->load(1); + $this->assertEquals(3, $entity->getRevisionId(), 'Default revision has been set correctly.'); } /**