Chris@0: routeMatch = $route_match; Chris@0: $this->helpManager = $help_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container) { Chris@0: return new static( Chris@0: $container->get('current_route_match'), Chris@0: $container->get('plugin.manager.help_section') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prints a page listing various types of help. Chris@0: * Chris@0: * The page has sections defined by \Drupal\help\HelpSectionPluginInterface Chris@0: * plugins. Chris@0: * Chris@0: * @return array Chris@0: * A render array for the help page. Chris@0: */ Chris@0: public function helpMain() { Chris@0: $output = []; Chris@0: Chris@0: // We are checking permissions, so add the user.permissions cache context. Chris@0: $cacheability = new CacheableMetadata(); Chris@0: $cacheability->addCacheContexts(['user.permissions']); Chris@0: Chris@0: $plugins = $this->helpManager->getDefinitions(); Chris@0: $cacheability->addCacheableDependency($this->helpManager); Chris@0: Chris@0: foreach ($plugins as $plugin_id => $plugin_definition) { Chris@0: // Check the provided permission. Chris@0: if (!empty($plugin_definition['permission']) && !$this->currentuser()->hasPermission($plugin_definition['permission'])) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: // Add the section to the page. Chris@0: /** @var \Drupal\help\HelpSectionPluginInterface $plugin */ Chris@0: $plugin = $this->helpManager->createInstance($plugin_id); Chris@0: $this_output = [ Chris@0: '#theme' => 'help_section', Chris@0: '#title' => $plugin->getTitle(), Chris@0: '#description' => $plugin->getDescription(), Chris@0: '#empty' => $this->t('There is currently nothing in this section.'), Chris@0: '#links' => [], Chris@0: ]; Chris@0: Chris@0: $links = $plugin->listTopics(); Chris@0: if (is_array($links) && count($links)) { Chris@0: $this_output['#links'] = $links; Chris@0: } Chris@0: Chris@0: $cacheability->addCacheableDependency($plugin); Chris@0: $output[$plugin_id] = $this_output; Chris@0: } Chris@0: Chris@0: $cacheability->applyTo($output); Chris@0: return $output; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prints a page listing general help for a module. Chris@0: * Chris@0: * @param string $name Chris@0: * A module name to display a help page for. Chris@0: * Chris@0: * @return array Chris@16: * A render array as expected by Chris@16: * \Drupal\Core\Render\RendererInterface::render(). Chris@0: * Chris@0: * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException Chris@0: */ Chris@0: public function helpPage($name) { Chris@0: $build = []; Chris@0: if ($this->moduleHandler()->implementsHook($name, 'help')) { Chris@0: $module_name = $this->moduleHandler()->getName($name); Chris@0: $build['#title'] = $module_name; Chris@0: Chris@0: $info = system_get_info('module', $name); Chris@0: if ($info['package'] === 'Core (Experimental)') { Chris@17: $this->messenger()->addWarning($this->t('This module is experimental. Experimental modules are provided for testing purposes only. Use at your own risk.', [':url' => 'https://www.drupal.org/core/experimental'])); Chris@0: } Chris@0: Chris@0: $temp = $this->moduleHandler()->invoke($name, 'help', ["help.page.$name", $this->routeMatch]); Chris@0: if (empty($temp)) { Chris@0: $build['top'] = ['#markup' => $this->t('No help is available for module %module.', ['%module' => $module_name])]; Chris@0: } Chris@0: else { Chris@0: if (!is_array($temp)) { Chris@0: $temp = ['#markup' => $temp]; Chris@0: } Chris@0: $build['top'] = $temp; Chris@0: } Chris@0: Chris@0: // Only print list of administration pages if the module in question has Chris@0: // any such pages associated with it. Chris@0: $admin_tasks = system_get_module_admin_tasks($name, system_get_info('module', $name)); Chris@0: if (!empty($admin_tasks)) { Chris@0: $links = []; Chris@0: foreach ($admin_tasks as $task) { Chris@0: $link['url'] = $task['url']; Chris@0: $link['title'] = $task['title']; Chris@0: $links[] = $link; Chris@0: } Chris@0: $build['links'] = [ Chris@0: '#theme' => 'links__help', Chris@0: '#heading' => [ Chris@0: 'level' => 'h3', Chris@0: 'text' => $this->t('@module administration pages', ['@module' => $module_name]), Chris@0: ], Chris@0: '#links' => $links, Chris@0: ]; Chris@0: } Chris@0: return $build; Chris@0: } Chris@0: else { Chris@0: throw new NotFoundHttpException(); Chris@0: } Chris@0: } Chris@0: Chris@0: }