You are here

public function HelpController::helpMain in Drupal 8

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

Prints a page listing various types of help.

The page has sections defined by \Drupal\help\HelpSectionPluginInterface plugins.

Return value

array A render array for the help page.

1 string reference to 'HelpController::helpMain'
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 80

Class

HelpController
Controller routines for help routes.

Namespace

Drupal\help\Controller

Code

public function helpMain() {
  $output = [];

  // We are checking permissions, so add the user.permissions cache context.
  $cacheability = new CacheableMetadata();
  $cacheability
    ->addCacheContexts([
    'user.permissions',
  ]);
  $plugins = $this->helpManager
    ->getDefinitions();
  $cacheability
    ->addCacheableDependency($this->helpManager);
  foreach ($plugins as $plugin_id => $plugin_definition) {

    // Check the provided permission.
    if (!empty($plugin_definition['permission']) && !$this
      ->currentuser()
      ->hasPermission($plugin_definition['permission'])) {
      continue;
    }

    // Add the section to the page.

    /** @var \Drupal\help\HelpSectionPluginInterface $plugin */
    $plugin = $this->helpManager
      ->createInstance($plugin_id);
    $this_output = [
      '#theme' => 'help_section',
      '#title' => $plugin
        ->getTitle(),
      '#description' => $plugin
        ->getDescription(),
      '#empty' => $this
        ->t('There is currently nothing in this section.'),
      '#links' => [],
      '#weight' => $plugin_definition['weight'],
    ];
    $links = $plugin
      ->listTopics();
    if (is_array($links) && count($links)) {
      $this_output['#links'] = $links;
    }
    $cacheability
      ->addCacheableDependency($plugin);
    $output[$plugin_id] = $this_output;
  }
  $cacheability
    ->applyTo($output);
  return $output;
}