You are here

public function HelpController::helpPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/help/src/Controller/HelpController.php \Drupal\help\Controller\HelpController::helpPage()

Prints a page listing general help for a module.

Parameters

string $name: A module name to display a help page for.

Return value

array A render array as expected by \Drupal\Core\Render\RendererInterface::render().

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

1 string reference to 'HelpController::helpPage'
help.routing.yml in core/modules/help/help.routing.yml
core/modules/help/help.routing.yml

File

core/modules/help/src/Controller/HelpController.php, line 133

Class

HelpController
Controller routines for help routes.

Namespace

Drupal\help\Controller

Code

public function helpPage($name) {
  $build = [];
  if ($this
    ->moduleHandler()
    ->implementsHook($name, 'help')) {
    $module_name = $this
      ->moduleHandler()
      ->getName($name);
    $build['#title'] = $module_name;
    $info = $this->moduleExtensionList
      ->getExtensionInfo($name);
    if ($info['package'] === 'Core (Experimental)') {
      $this
        ->messenger()
        ->addWarning($this
        ->t('This module is experimental. <a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', [
        ':url' => 'https://www.drupal.org/core/experimental',
      ]));
    }
    $temp = $this
      ->moduleHandler()
      ->invoke($name, 'help', [
      "help.page.{$name}",
      $this->routeMatch,
    ]);
    if (empty($temp)) {
      $build['top'] = [
        '#markup' => $this
          ->t('No help is available for module %module.', [
          '%module' => $module_name,
        ]),
      ];
    }
    else {
      if (!is_array($temp)) {
        $temp = [
          '#markup' => $temp,
        ];
      }
      $build['top'] = $temp;
    }

    // Only print list of administration pages if the module in question has
    // any such pages associated with it.
    $admin_tasks = system_get_module_admin_tasks($name, $info);
    if (!empty($admin_tasks)) {
      $links = [];
      foreach ($admin_tasks as $task) {
        $link['url'] = $task['url'];
        $link['title'] = $task['title'];
        $links[] = $link;
      }
      $build['links'] = [
        '#theme' => 'links__help',
        '#heading' => [
          'level' => 'h3',
          'text' => $this
            ->t('@module administration pages', [
            '@module' => $module_name,
          ]),
        ],
        '#links' => $links,
      ];
    }
    return $build;
  }
  else {
    throw new NotFoundHttpException();
  }
}