function HelpController::helpPage

Same name in other branches
  1. 9 core/modules/help/src/Controller/HelpController.php \Drupal\help\Controller\HelpController::helpPage()
  2. 8.9.x core/modules/help/src/Controller/HelpController.php \Drupal\help\Controller\HelpController::helpPage()
  3. 10 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 119

Class

HelpController
Controller routines for help routes.

Namespace

Drupal\help\Controller

Code

public function helpPage($name) {
    $build = [];
    if ($this->moduleHandler()
        ->hasImplementations('help', $name)) {
        $module_name = $this->moduleExtensionList
            ->getName($name);
        $build['#title'] = $module_name;
        $info = $this->moduleExtensionList
            ->getExtensionInfo($name);
        if ($info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::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 = $this->moduleAdminLinks
            ->getModuleAdminLinks($name);
        if ($module_permissions_link = $this->modulePermissionsLinks
            ->getModulePermissionsLink($name, $info['name'])) {
            $admin_tasks["user.admin_permissions.{$name}"] = $module_permissions_link;
        }
        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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.