Skip to content
Snippets Groups Projects
Select Git revision
  • 2e19b481ae7c82427768626738b930bd66e20ac6
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

SystemHelpBlock.php

Blame
  • Nathaniel Catchpole's avatar
    Issue #1831846 by katbailey, maciej.zgadzaj, dawehner, RobLoach, moe4715,...
    catch authored
    Issue #1831846 by katbailey, maciej.zgadzaj, dawehner, RobLoach, moe4715, Hydra, larowlan, andypost: Fixed Help block is broken with language path prefixes.
    2e19b481
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    SystemHelpBlock.php 3.14 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\system\Plugin\Block\SystemHelpBlock.
     */
    
    namespace Drupal\system\Plugin\Block;
    
    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.
     *
     * @Block(
     *   id = "system_help_block",
     *   admin_label = @Translation("System Help")
     * )
     */
    class SystemHelpBlock extends BlockBase implements ContainerFactoryPluginInterface {
    
      /**
       * Stores the help text associated with the active menu item.
       *
       * @var string
       */
      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 = $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}
       */
      public function build() {
        return array(
          '#children' => $this->help,
        );
      }
    
    }