Loading core/modules/node/src/Form/NodeRevisionRevertForm.php +4 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * The prepared revision ready to be stored. */ protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) { return $this->nodeStorage->createRevision($revision); $revision->setNewRevision(); $revision->isDefaultRevision(TRUE); return $revision; } } core/modules/node/tests/src/Functional/NodeRevisionsTest.php +1 −37 Original line number Diff line number Diff line Loading @@ -453,9 +453,7 @@ public function testRevisionTranslationRevert(): void { $node = $node_storage->load($node->id()); $this->assertGreaterThan($latest_revision_id, $node->getRevisionId()); $this->assertEquals($initial_title, $node->label()); // The node should retain the translations from the last default revision. // @see \Drupal\Core\Entity\ContentEntityStorageBase::createRevision. $this->assertTrue($node->hasTranslation('it')); $this->assertFalse($node->hasTranslation('it')); } /** Loading @@ -475,38 +473,4 @@ protected function createRevisions(NodeInterface $node, $count): void { } } /** * Tests the Set as current revision link. * * This operation appears on the revision list when there is a more recent * revision than the current revision. */ public function testSetAsCurrentRevision(): void { $node = $this->drupalCreateNode(); // Create a non-default revision. $node->setNewRevision(); $node->isDefaultRevision(FALSE); $node->body->value = '<p>new body</p>'; $node->setRevisionLogMessage('non default revision message'); $node->save(); $this->drupalGet($node->toUrl('version-history')); $this->assertSession()->linkExists('Set as current revision'); $this->clickLink('Set as current revision'); $this->submitForm([], 'Revert'); $this->assertSession()->pageTextContains(sprintf('Basic page %s has been reverted', $node->label())); // Reverting the non-default revision should create a new revision and set // it as the default, meaning there should be 3 revisions displayed and no // Set as current revision link. $this->assertSession()->elementsCount('css', '.node-revision-table tbody tr', 3); $this->assertSession()->linkNotExists('Set as current revision'); $this->assertSession()->pageTextContains('Copy of the revision from'); // The first row (the revision we just reverted to) should be displayed as // the current revision. $firstRowSecondColumnText = $this->getSession()->getPage()->find('xpath', '//tbody/tr[1]/td[2]/em')->getText(); $this->assertEquals('Current revision', $firstRowSecondColumnText); } } Loading
core/modules/node/src/Form/NodeRevisionRevertForm.php +4 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * The prepared revision ready to be stored. */ protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) { return $this->nodeStorage->createRevision($revision); $revision->setNewRevision(); $revision->isDefaultRevision(TRUE); return $revision; } }
core/modules/node/tests/src/Functional/NodeRevisionsTest.php +1 −37 Original line number Diff line number Diff line Loading @@ -453,9 +453,7 @@ public function testRevisionTranslationRevert(): void { $node = $node_storage->load($node->id()); $this->assertGreaterThan($latest_revision_id, $node->getRevisionId()); $this->assertEquals($initial_title, $node->label()); // The node should retain the translations from the last default revision. // @see \Drupal\Core\Entity\ContentEntityStorageBase::createRevision. $this->assertTrue($node->hasTranslation('it')); $this->assertFalse($node->hasTranslation('it')); } /** Loading @@ -475,38 +473,4 @@ protected function createRevisions(NodeInterface $node, $count): void { } } /** * Tests the Set as current revision link. * * This operation appears on the revision list when there is a more recent * revision than the current revision. */ public function testSetAsCurrentRevision(): void { $node = $this->drupalCreateNode(); // Create a non-default revision. $node->setNewRevision(); $node->isDefaultRevision(FALSE); $node->body->value = '<p>new body</p>'; $node->setRevisionLogMessage('non default revision message'); $node->save(); $this->drupalGet($node->toUrl('version-history')); $this->assertSession()->linkExists('Set as current revision'); $this->clickLink('Set as current revision'); $this->submitForm([], 'Revert'); $this->assertSession()->pageTextContains(sprintf('Basic page %s has been reverted', $node->label())); // Reverting the non-default revision should create a new revision and set // it as the default, meaning there should be 3 revisions displayed and no // Set as current revision link. $this->assertSession()->elementsCount('css', '.node-revision-table tbody tr', 3); $this->assertSession()->linkNotExists('Set as current revision'); $this->assertSession()->pageTextContains('Copy of the revision from'); // The first row (the revision we just reverted to) should be displayed as // the current revision. $firstRowSecondColumnText = $this->getSession()->getPage()->find('xpath', '//tbody/tr[1]/td[2]/em')->getText(); $this->assertEquals('Current revision', $firstRowSecondColumnText); } }