From 5ba8499ecdd202b993d5c5725e682ee48ac6a96b Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Fri, 13 May 2016 11:55:30 +0100
Subject: [PATCH] =?UTF-8?q?Issue=20#2713587=20by=20tduong,=20mkalkbrenner,?=
 =?UTF-8?q?=20Berdir,=20G=C3=A1bor=20Hojtsy:=20NodeController::revisionOve?=
 =?UTF-8?q?rview()=20shows=20no=20revisions=20if=20node=20has=20no=20trans?=
 =?UTF-8?q?lation=20for=20current=20language?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

(cherry picked from commit 934a4b402d0ef9a2c5fcdb2117f2cd979f99eeb0)
---
 .../node/src/Controller/NodeController.php    |  7 ++-
 .../node/src/Tests/NodeRevisionsTest.php      | 57 +++++++++++++++++++
 2 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php
index edb5682311b3..9fbd6035087d 100644
--- a/core/modules/node/src/Controller/NodeController.php
+++ b/core/modules/node/src/Controller/NodeController.php
@@ -6,7 +6,6 @@
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\Datetime\DateFormatterInterface;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
-use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Url;
 use Drupal\node\NodeTypeInterface;
@@ -157,8 +156,8 @@ public function revisionPageTitle($node_revision) {
    */
   public function revisionOverview(NodeInterface $node) {
     $account = $this->currentUser();
-    $langcode = $this->languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
-    $langname = $this->languageManager()->getLanguageName($langcode);
+    $langcode = $node->language()->getId();
+    $langname = $node->language()->getName();
     $languages = $node->getTranslationLanguages();
     $has_translations = (count($languages) > 1);
     $node_storage = $this->entityManager()->getStorage('node');
@@ -179,6 +178,8 @@ public function revisionOverview(NodeInterface $node) {
     foreach (array_reverse($vids) as $vid) {
       /** @var \Drupal\node\NodeInterface $revision */
       $revision = $node_storage->loadRevision($vid);
+      // Only show revisions that are affected by the language that is being
+      // displayed.
       if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
         $username = [
           '#theme' => 'username',
diff --git a/core/modules/node/src/Tests/NodeRevisionsTest.php b/core/modules/node/src/Tests/NodeRevisionsTest.php
index a1047f59df39..de8288e8d1fc 100644
--- a/core/modules/node/src/Tests/NodeRevisionsTest.php
+++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
@@ -42,6 +42,8 @@ class NodeRevisionsTest extends NodeTestBase {
   protected function setUp() {
     parent::setUp();
 
+    // Enable additional languages.
+    ConfigurableLanguage::createFromLangcode('de')->save();
     ConfigurableLanguage::createFromLangcode('it')->save();
 
     $field_storage_definition = array(
@@ -70,6 +72,7 @@ protected function setUp() {
         'edit any page content',
         'delete any page content',
         'translate any entity',
+        'administer content types',
       )
     );
 
@@ -211,6 +214,60 @@ function testRevisions() {
       ->fetchCol();
     $default_revision_vid = $default_revision[0];
     $this->assertTrue($new_node_revision->getRevisionId() > $default_revision_vid, 'Revision vid is greater than default revision vid.');
+
+    // Create an 'EN' node with a revision log message.
+    $node = $this->drupalCreateNode();
+    $node->title = 'Node title in EN';
+    $node->revision_log = 'Simple revision message (EN)';
+    $node->save();
+
+    $this->drupalGet("node/" . $node->id() . "/revisions");
+    $this->assertResponse(403);
+
+    // Create a new revision and new log message.
+    $node = Node::load($node->id());
+    $node->body->value = 'New text (EN)';
+    $node->revision_log = 'New revision message (EN)';
+    $node->setNewRevision();
+    $node->save();
+
+    // Check both revisions are shown on the node revisions overview page.
+    $this->drupalGet("node/" . $node->id() . "/revisions");
+    $this->assertText('Simple revision message (EN)');
+    $this->assertText('New revision message (EN)');
+
+    // Create an 'EN' node with a revision log message.
+    $node = $this->drupalCreateNode();
+    $node->langcode = 'en';
+    $node->title = 'Node title in EN';
+    $node->revision_log = 'Simple revision message (EN)';
+    $node->save();
+
+    $this->drupalGet("node/" . $node->id() . "/revisions");
+    $this->assertResponse(403);
+
+    // Add a translation in 'DE' and create a new revision and new log message.
+    $translation = $node->addTranslation('de');
+    $translation->title->value = 'Node title in DE';
+    $translation->body->value = 'New text (DE)';
+    $translation->revision_log = 'New revision message (DE)';
+    $translation->setNewRevision();
+    $translation->save();
+
+    // View the revision UI in 'IT', only the original node revision is shown.
+    $this->drupalGet("it/node/" . $node->id() . "/revisions");
+    $this->assertText('Simple revision message (EN)');
+    $this->assertNoText('New revision message (DE)');
+
+    // View the revision UI in 'DE', only the translated node revision is shown.
+    $this->drupalGet("de/node/" . $node->id() . "/revisions");
+    $this->assertNoText('Simple revision message (EN)');
+    $this->assertText('New revision message (DE)');
+
+    // View the revision UI in 'EN', only the original node revision is shown.
+    $this->drupalGet("node/" . $node->id() . "/revisions");
+    $this->assertText('Simple revision message (EN)');
+    $this->assertNoText('New revision message (DE)');
   }
 
   /**
-- 
GitLab