diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index 8fd04b6..aeb25db 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -173,7 +173,7 @@ public function revisionOverview(NodeInterface $node) { $vids = $node_storage->revisionIds($node); - $latest_revision = TRUE; + $default_revision = $node->getRevisionId(); foreach (array_reverse($vids) as $vid) { /** @var \Drupal\node\NodeInterface $revision */ @@ -211,7 +211,7 @@ public function revisionOverview(NodeInterface $node) { $this->renderer->addCacheableDependency($column['data'], $username); $row[] = $column; - if ($latest_revision) { + if ($vid == $default_revision) { $row[] = [ 'data' => [ '#prefix' => '', @@ -219,16 +219,17 @@ public function revisionOverview(NodeInterface $node) { '#suffix' => '', ], ]; - foreach ($row as &$current) { - $current['class'] = ['revision-current']; - } - $latest_revision = FALSE; + + $rows[] = [ + 'data' => $row, + 'class' => ['revision-current'], + ]; } else { $links = []; if ($revert_permission) { $links['revert'] = [ - 'title' => $this->t('Revert'), + 'title' => $vid < $node->getRevisionId() ? $this->t('Revert') : $this->t('Set as current revision'), 'url' => $has_translations ? Url::fromRoute('node.revision_revert_translation_confirm', ['node' => $node->id(), 'node_revision' => $vid, 'langcode' => $langcode]) : Url::fromRoute('node.revision_revert_confirm', ['node' => $node->id(), 'node_revision' => $vid]), @@ -248,9 +249,9 @@ public function revisionOverview(NodeInterface $node) { '#links' => $links, ], ]; - } - $rows[] = $row; + $rows[] = $row; + } } } @@ -261,6 +262,7 @@ public function revisionOverview(NodeInterface $node) { '#attached' => array( 'library' => array('node/drupal.node.admin'), ), + '#attributes' => ['class' => 'node-revision-table'], ); return $build; diff --git a/core/modules/node/src/Tests/NodeRevisionsUiTest.php b/core/modules/node/src/Tests/NodeRevisionsUiTest.php index 278809a..cf609b8 100644 --- a/core/modules/node/src/Tests/NodeRevisionsUiTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsUiTest.php @@ -121,4 +121,43 @@ public function testNodeRevisionDoubleEscapeFix() { $this->assertRaw($nodes[1]->link($date) . ' by ' . $editor . '

' . $revision_log . '

'); } + /** + * Checks the Revisions tab. + */ + public function testNodeRevisionsTabWithDefaultRevision() { + $this->drupalLogin($this->editor); + + // Create the node. + $node = $this->drupalCreateNode(); + + $node->setNewRevision(TRUE); + $node->save(); + $node->setNewRevision(TRUE); + $node->save(); + $node->isDefaultRevision(FALSE); + $node->setNewRevision(TRUE); + $node->save(); + $node->isDefaultRevision(FALSE); + $node->setNewRevision(TRUE); + $node->save(); + + $node_id = $node->id(); + + $this->drupalGet('node/' . $node_id . '/revisions'); + + // Verify that the default revision can be an older revision than the latest + // one. + $this->assertLinkByHref('/node/' . $node_id . '/revisions/5/revert'); + $this->assertLinkByHref('/node/' . $node_id . '/revisions/4/revert'); + $this->assertNoLinkByHref('/node/' . $node_id . '/revisions/3/revert'); + $current_revision_row = $this->xpath("//table[contains(@class, :table_class)]//tbody//tr[3 and contains(@class, :class) and contains(., :text)]", [ + ':table_class' => 'node-revision-table', + ':class' => 'revision-current', + ':text' => 'Current revision', + ]); + $this->assertEqual(count($current_revision_row), 1, 'The default revision can be a revision other than the latest one.'); + $this->assertLinkByHref('/node/' . $node_id . '/revisions/2/revert'); + $this->assertLinkByHref('/node/' . $node_id . '/revisions/1/revert'); + } + }