Commit ec4bfd91 authored by catch's avatar catch

Issue #2761409 by timmillwood, hgoto: The latest revision isn't always the current revision

parent e17761e4
......@@ -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' => '<em>',
......@@ -219,16 +219,17 @@ public function revisionOverview(NodeInterface $node) {
'#suffix' => '</em>',
],
];
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;
......
......@@ -121,4 +121,43 @@ public function testNodeRevisionDoubleEscapeFix() {
$this->assertRaw($nodes[1]->link($date) . ' by ' . $editor . '<p class="revision-log">' . $revision_log . '</p>');
}
/**
* 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');
}
}
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