From 2e19b481ae7c82427768626738b930bd66e20ac6 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Fri, 20 Sep 2013 14:44:12 +0100
Subject: [PATCH] Issue #1831846 by katbailey, maciej.zgadzaj, dawehner,
 RobLoach, moe4715, Hydra, larowlan, andypost: Fixed Help block is broken with
 language path prefixes.

---
 core/includes/menu.inc                        | 23 ------
 .../node/Tests/NodeTranslationUITest.php      |  3 +-
 .../system/Plugin/Block/SystemHelpBlock.php   | 77 ++++++++++++++++++-
 3 files changed, 77 insertions(+), 26 deletions(-)

diff --git a/core/includes/menu.inc b/core/includes/menu.inc
index 7c431d414740..49627d1a0f88 100644
--- a/core/includes/menu.inc
+++ b/core/includes/menu.inc
@@ -1784,29 +1784,6 @@ function drupal_help_arg($arg = array()) {
   return $arg + array('', '', '', '', '', '', '', '', '', '', '', '');
 }
 
-/**
- * Returns the help associated with the active menu item.
- */
-function menu_get_active_help() {
-  $output = '';
-  $router_path = menu_tab_root_path();
-  // We will always have a path unless we are on a 403 or 404.
-  if (!$router_path) {
-    return '';
-  }
-
-  $arg = drupal_help_arg(arg(NULL));
-
-  foreach (\Drupal::moduleHandler()->getImplementations('help') as $module) {
-    $function = $module . '_help';
-    // Lookup help for this path.
-    if ($help = $function($router_path, $arg)) {
-      $output .= $help . "\n";
-    }
-  }
-  return $output;
-}
-
 /**
  * Gets the custom theme for the current page, if there is one.
  *
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php
index c8be00bbf8cf..77c0bbd5a63b 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php
@@ -25,7 +25,7 @@ class NodeTranslationUITest extends ContentTranslationUITest {
    *
    * @var array
    */
-  public static $modules = array('language', 'content_translation', 'node', 'datetime', 'field_ui');
+  public static $modules = array('block', 'language', 'content_translation', 'node', 'datetime', 'field_ui');
 
   public static function getInfo() {
     return array(
@@ -40,6 +40,7 @@ function setUp() {
     $this->bundle = 'article';
     $this->title = $this->randomName();
     parent::setUp();
+    $this->drupalPlaceBlock('system_help_block', array('region' => 'content'));
   }
 
   /**
diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php
index 23520a302d17..48ad76febed1 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php
@@ -10,6 +10,10 @@
 use Drupal\block\BlockBase;
 use Drupal\block\Annotation\Block;
 use Drupal\Core\Annotation\Translation;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\Request;
 
 /**
  * Provides a 'System Help' block.
@@ -19,7 +23,7 @@
  *   admin_label = @Translation("System Help")
  * )
  */
-class SystemHelpBlock extends BlockBase {
+class SystemHelpBlock extends BlockBase implements ContainerFactoryPluginInterface {
 
   /**
    * Stores the help text associated with the active menu item.
@@ -28,14 +32,83 @@ class SystemHelpBlock extends BlockBase {
    */
   protected $help;
 
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * The current request.
+   *
+   * @var \Symfony\Component\HttpFoundation\Request
+   */
+  protected $request;
+
+  /**
+   * Creates a SystemHelpBlock instance.
+   *
+   * @param array $configuration
+   *   A configuration array containing information about the plugin instance.
+   * @param string $plugin_id
+   *   The plugin_id for the plugin instance.
+   * @param array $plugin_definition
+   *   The plugin implementation definition.
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   The current request.
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
+   */
+  public function __construct(array $configuration, $plugin_id, array $plugin_definition, Request $request, ModuleHandlerInterface $module_handler) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+
+    $this->request = $request;
+    $this->moduleHandler = $module_handler;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
+    return new static(
+      $configuration, $plugin_id, $plugin_definition, $container->get('request'), $container->get('module_handler'));
+  }
+
   /**
    * Overrides \Drupal\block\BlockBase::access().
    */
   public function access() {
-    $this->help = menu_get_active_help();
+    $this->help = $this->getActiveHelp($this->request);
     return (bool) $this->help;
   }
 
+  /**
+   * Returns the help associated with the active menu item.
+   *
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   The current request.
+   */
+  protected function getActiveHelp(Request $request) {
+    $output = '';
+    $router_path = menu_tab_root_path();
+    // We will always have a path unless we are on a 403 or 404.
+    if (!$router_path) {
+      return '';
+    }
+
+    $arg = drupal_help_arg(explode('/', $request->attributes->get('_system_path')));
+
+    foreach ($this->moduleHandler->getImplementations('help') as $module) {
+      $function = $module . '_help';
+      // Lookup help for this path.
+      if ($help = $function($router_path, $arg)) {
+        $output .= $help . "\n";
+      }
+    }
+    return $output;
+  }
+
   /**
    * {@inheritdoc}
    */
-- 
GitLab