summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-07-12 13:18:53 (GMT)
committerNathaniel Catchpole2016-07-12 13:18:53 (GMT)
commitec4bfd91644543023def411c40802cb42988fe74 (patch)
treec093758631bd4331e175a58aa690d9b3ebb6c8a0
parente17761e462437f701feb79539bce4d562d80255b (diff)
Issue #2761409 by timmillwood, hgoto: The latest revision isn't always the current revision
-rw-r--r--core/modules/node/src/Controller/NodeController.php20
-rw-r--r--core/modules/node/src/Tests/NodeRevisionsUiTest.php39
2 files changed, 50 insertions, 9 deletions
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 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
$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 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
$this->renderer->addCacheableDependency($column['data'], $username);
$row[] = $column;
- if ($latest_revision) {
+ if ($vid == $default_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
@@ -219,16 +219,17 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
'#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 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
'#links' => $links,
],
];
- }
- $rows[] = $row;
+ $rows[] = $row;
+ }
}
}
@@ -261,6 +262,7 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
'#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 @@ class NodeRevisionsUiTest extends NodeTestBase {
$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');
+ }
+
}