diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index 48401475fc..e873f91f56 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -173,6 +173,7 @@ public function revisionOverview(NodeInterface $node) { $rows = []; $default_revision = $node->getRevisionId(); + $current_revision_displayed = FALSE; foreach ($this->getRevisionIds($node, $node_storage) as $vid) { /** @var \Drupal\node\NodeInterface $revision */ @@ -187,11 +188,18 @@ public function revisionOverview(NodeInterface $node) { // Use revision link to link to revisions that are not active. $date = $this->dateFormatter->format($revision->revision_timestamp->value, 'short'); - if ($vid != $node->getRevisionId()) { + + // We treat also the latest translation-affecting revision as current + // revision, if it was the default revision, as its values for the + // current language will be the same of the current default revision in + // this case. + $is_current_revision = $vid == $default_revision || (!$current_revision_displayed && $revision->wasDefaultRevision()); + if (!$is_current_revision) { $link = $this->l($date, new Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid])); } else { $link = $node->link($date); + $current_revision_displayed = TRUE; } $row = []; @@ -210,7 +218,7 @@ public function revisionOverview(NodeInterface $node) { $this->renderer->addCacheableDependency($column['data'], $username); $row[] = $column; - if ($vid == $default_revision) { + if ($is_current_revision) { $row[] = [ 'data' => [ '#prefix' => '', diff --git a/core/modules/node/src/Form/NodeRevisionRevertForm.php b/core/modules/node/src/Form/NodeRevisionRevertForm.php index fc6fe023f5..e18ad77610 100644 --- a/core/modules/node/src/Form/NodeRevisionRevertForm.php +++ b/core/modules/node/src/Form/NodeRevisionRevertForm.php @@ -28,7 +28,7 @@ class NodeRevisionRevertForm extends ConfirmFormBase { /** * The node storage. * - * @var \Drupal\Core\Entity\EntityStorageInterface + * @var \Drupal\node\NodeStorageInterface */ protected $nodeStorage; diff --git a/core/modules/node/src/Form/NodeRevisionRevertTranslationForm.php b/core/modules/node/src/Form/NodeRevisionRevertTranslationForm.php index eb07b7af44..a6a4d85d8a 100644 --- a/core/modules/node/src/Form/NodeRevisionRevertTranslationForm.php +++ b/core/modules/node/src/Form/NodeRevisionRevertTranslationForm.php @@ -106,24 +106,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $node_rev * {@inheritdoc} */ protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state) { - $revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields'); - - /** @var \Drupal\node\NodeInterface $default_revision */ - $latest_revision = $this->nodeStorage->load($revision->id()); - $latest_revision_translation = $latest_revision->getTranslation($this->langcode); - - $revision_translation = $revision->getTranslation($this->langcode); - - foreach ($latest_revision_translation->getFieldDefinitions() as $field_name => $definition) { - if ($definition->isTranslatable() || $revert_untranslated_fields) { - $latest_revision_translation->set($field_name, $revision_translation->get($field_name)->getValue()); - } - } - - $latest_revision_translation->setNewRevision(); - $latest_revision_translation->isDefaultRevision(TRUE); - - return $latest_revision_translation; + $revert_untranslated_fields = (bool) $form_state->getValue('revert_untranslated_fields'); + $translation = $revision->getTranslation($this->langcode); + return $this->nodeStorage->createRevision($translation, TRUE, $revert_untranslated_fields); } } diff --git a/core/modules/node/src/Tests/NodeRevisionsTest.php b/core/modules/node/src/Tests/NodeRevisionsTest.php index da5b260537..066193ddab 100644 --- a/core/modules/node/src/Tests/NodeRevisionsTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php @@ -64,6 +64,9 @@ protected function setUp() { $field = FieldConfig::create($field_definition); $field->save(); + // Enable translation for page nodes. + \Drupal::service('content_translation.manager')->setEnabled('node', 'page', TRUE); + // Create and log in user. $web_user = $this->drupalCreateUser( [ diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php index a437e4aba8..3646ab3e01 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php @@ -160,10 +160,17 @@ public function testNodeRevisionsTabWithDefaultRevision() { $this->drupalGet('node/' . $node_id . '/revisions'); + // Verify that the latest affected revision having been a default revision + // is displayed as the current one. + $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/1/revert'); + $elements = $this->xpath('//tr[contains(@class, "revision-current")]/td/a[1]'); + // The site may be installed in a subdirectory, so check if the URL is + // contained in the retrieved one. + $this->assertContains('/node/1', current($elements)->getAttribute('href')); + // Verify that the default revision can be an older revision than the latest // one. - // Assert that the revisions with translations changes are shown: 1 and 4. - $this->assertLinkByHref('/node/' . $node_id . '/revisions/1/revert'); + // Assert that the revisions with translations changes are shown. $this->assertLinkByHref('/node/' . $node_id . '/revisions/4/revert'); // Assert that the revisions without translations changes are filtered out: