From 685f3a060ddaf3c78389fa275a63c7f0e9aa2f21 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Fri, 12 Jun 2020 17:24:48 +1000
Subject: [PATCH] Issue #3020387 by Sam152, luisnicg, bahuma20, jungle:
 Moderation state is the same for all node's translations in edit page

---
 .../Field/ModerationStateFieldItemList.php    |  1 +
 .../ModerationStateFieldItemListTest.php      | 29 +++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
index 679fca92db26..7e717881cfd8 100644
--- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
+++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
@@ -81,6 +81,7 @@ protected function loadContentModerationStateRevision(ContentEntityInterface $en
       // being reverted.
       ->condition('content_entity_revision_id', $entity->isNewRevision() ? $entity->getLoadedRevisionId() : $entity->getRevisionId())
       ->condition('workflow', $moderation_info->getWorkflowForEntity($entity)->id())
+      ->condition('langcode', $entity->language()->getId())
       ->allRevisions()
       ->sort('revision_id', 'DESC')
       ->execute();
diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
index 0e74b1ae0e73..92423626c580 100644
--- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php
@@ -401,4 +401,33 @@ public function testWithExistingUnmoderatedContent() {
     $this->assertEquals('published', $translation->moderation_state->value);
   }
 
+  /**
+   * Tests field item list translation support with unmoderated content.
+   */
+  public function testTranslationWithExistingUnmoderatedContent() {
+    $node = Node::create([
+      'title' => 'Published en',
+      'langcode' => 'en',
+      'type' => 'unmoderated',
+    ]);
+    $node->setPublished();
+    $node->save();
+
+    $workflow = Workflow::load('editorial');
+    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'unmoderated');
+    $workflow->save();
+
+    $translation = $node->addTranslation('de');
+    $translation->moderation_state = 'draft';
+    $translation->save();
+
+    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
+    $node = $node_storage->loadRevision($node_storage->getLatestRevisionId($node->id()));
+
+    $this->assertEquals('published', $node->moderation_state->value);
+    $this->assertEquals('draft', $translation->moderation_state->value);
+    $this->assertTrue($node->isPublished());
+    $this->assertFalse($translation->isPublished());
+  }
+
 }
-- 
GitLab