From 57bbb6f5655438b3dcdeae7a351db120fb52a5b2 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 26 Aug 2016 14:13:05 +0100
Subject: [PATCH] Issue #2788487 by timmillwood: Manage moderation tab not
 displaying on bundle admin

---
 .../src/Plugin/Derivative/DynamicLocalTasks.php           | 7 ++++---
 .../src/Tests/ModerationStateBlockTest.php                | 8 +++++++-
 .../src/Tests/ModerationStateTestBase.php                 | 2 ++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php b/core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
index 84ad4aab385a..7ff1fa5da578 100644
--- a/core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
+++ b/core/modules/content_moderation/src/Plugin/Derivative/DynamicLocalTasks.php
@@ -78,11 +78,12 @@ public function getDerivativeDefinitions($base_plugin_definition) {
 
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
       if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
-        $this->derivatives["$entity_type_id.moderation_tab"] = [
-          'route_name' => "entity.$entity_type_id.moderation",
+        $bundle_id = $entity_type->getBundleEntityType();
+        $this->derivatives["$bundle_id.moderation_tab"] = [
+          'route_name' => "entity.$bundle_id.moderation",
           'title' => $this->t('Manage moderation'),
           // @todo - are we sure they all have an edit_form?
-          'base_route' => "entity.$entity_type_id.edit_form",
+          'base_route' => "entity.$bundle_id.edit_form",
           'weight' => 30,
         ] + $base_plugin_definition;
       }
diff --git a/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php b/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php
index 001d6b55ffad..03a4b0ee2d91 100644
--- a/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php
+++ b/core/modules/content_moderation/src/Tests/ModerationStateBlockTest.php
@@ -51,6 +51,12 @@ protected function setUp() {
   public function testCustomBlockModeration() {
     $this->drupalLogin($this->rootUser);
 
+    $this->drupalGet('admin/structure/block/block-content/types');
+    $this->assertLinkByHref('admin/structure/block/block-content/manage/basic/moderation');
+    $this->drupalGet('admin/structure/block/block-content/manage/basic');
+    $this->assertLinkByHref('admin/structure/block/block-content/manage/basic/moderation');
+    $this->drupalGet('admin/structure/block/block-content/manage/basic/moderation');
+
     // Enable moderation for custom blocks at
     // admin/structure/block/block-content/manage/basic/moderation.
     $edit = [
@@ -59,7 +65,7 @@ public function testCustomBlockModeration() {
       'allowed_moderation_states_published[published]' => TRUE,
       'default_moderation_state' => 'draft',
     ];
-    $this->drupalPostForm('admin/structure/block/block-content/manage/basic/moderation', $edit, t('Save'));
+    $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertText(t('Your settings have been saved.'));
 
     // Create a custom block at block/add and save it as draft.
diff --git a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php b/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php
index 0dbdc3df3baa..ddd275e6e4b4 100644
--- a/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php
+++ b/core/modules/content_moderation/src/Tests/ModerationStateTestBase.php
@@ -108,6 +108,8 @@ protected function createContentTypeFromUi($content_type_name, $content_type_id,
   protected function enableModerationThroughUi($content_type_id, array $allowed_states, $default_state) {
     $this->drupalGet('admin/structure/types');
     $this->assertLinkByHref('admin/structure/types/manage/' . $content_type_id . '/moderation');
+    $this->drupalGet('admin/structure/types/manage/' . $content_type_id);
+    $this->assertLinkByHref('admin/structure/types/manage/' . $content_type_id . '/moderation');
     $this->drupalGet('admin/structure/types/manage/' . $content_type_id . '/moderation');
     $this->assertFieldByName('enable_moderation_state');
     $this->assertNoFieldChecked('edit-enable-moderation-state');
-- 
GitLab