"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/help_topics/help_topics.module" (26 Nov 2020, 4706 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 /**
    4  * @file
    5  * Displays help topics provided by modules and themes.
    6  */
    7 
    8 use Drupal\Core\Routing\RouteMatchInterface;
    9 use Drupal\Core\Url;
   10 
   11 /**
   12  * Implements hook_help().
   13  */
   14 function help_topics_help($route_name, RouteMatchInterface $route_match) {
   15   switch ($route_name) {
   16     case 'help.page.help_topics':
   17       $help_home = Url::fromRoute('help.main')->toString();
   18       $module_handler = \Drupal::moduleHandler();
   19       $locale_help = ($module_handler->moduleExists('locale')) ? Url::fromRoute('help.page', ['name' => 'locale'])->toString() : '#';
   20       $search_help = ($module_handler->moduleExists('search')) ? Url::fromRoute('help.page', ['name' => 'search'])->toString() : '#';
   21       $output = '';
   22       $output .= '<h3>' . t('About') . '</h3>';
   23       $output .= '<p>' . t('The Help Topics module adds module- and theme-provided help topics to the module overviews from the core Help module. If the core Search module is enabled, these topics are also searchable. For more information, see the <a href=":online">online documentation for the Help Topics module</a>.', [':online' => 'https://www.drupal.org/documentation/modules/help_topics']) . '</p>';
   24       $output .= '<h3>' . t('Uses') . '</h3>';
   25       $output .= '<dl>';
   26       $output .= '<dt>' . t('Viewing help topics') . '</dt>';
   27       $output .= '<dd>' . t('The top-level help topics are listed on the main <a href=":help_page">Help page</a>. Links to other topics, including non-top-level help topics, can be found under the "Related" heading when viewing a topic page.', [':help_page' => $help_home]) . '</dd>';
   28       $output .= '<dt>' . t('Providing help topics') . '</dt>';
   29       $output .= '<dd>' . t("Modules and themes can provide help topics as Twig-file-based plugins in a project sub-directory called <em>help_topics</em>; plugin meta-data is provided in YAML front matter within each Twig file. Plugin-based help topics provided by modules and themes will automatically be updated when a module or theme is updated. Use the plugins in <em>core/modules/help_topics/help_topics</em> as a guide when writing and formatting a help topic plugin for your theme or module.") . '</dd>';
   30       $output .= '<dt>' . t('Translating help topics') . '</dt>';
   31       $output .= '<dd>' . t('The title and body text of help topics provided by contributed modules and themes are translatable using the <a href=":locale_help">Interface Translation module</a>. Topics provided by custom modules and themes are also translatable if they have been viewed at least once in a non-English language, which triggers putting their translatable text into the translation database.', [':locale_help' => $locale_help]) . '</dd>';
   32       $output .= '<dt>' . t('Configuring help search') . '</dt>';
   33       $output .= '<dd>' . t('To search help, you will need to install the core Search module, configure a search page, and add a search block to the Help page or another administrative page. (A search page is provided automatically, and if you use the core Seven administrative theme, a help search block is shown on the main Help page.) Then users with search permissions, and permission to view help, will be able to search help. See the <a href=":search_help">Search module help page</a> for more information.', [':search_help' => $search_help]) . '</dd>';
   34       $output .= '</dl>';
   35       return ['#markup' => $output];
   36 
   37     case 'help.help_topic':
   38       $help_home = Url::fromRoute('help.main')->toString();
   39       return '<p>' . t('See the <a href=":help_page">Help page</a> for more topics.', [
   40         ':help_page' => $help_home,
   41       ]) . '</p>';
   42   }
   43 }
   44 
   45 /**
   46  * Implements hook_theme().
   47  */
   48 function help_topics_theme() {
   49   return [
   50     'help_topic' => [
   51       'variables' => [
   52         'body' => [],
   53         'related' => [],
   54       ],
   55     ],
   56   ];
   57 }
   58 
   59 /**
   60  * Implements hook_modules_uninstalled().
   61  */
   62 function help_topics_modules_uninstalled(array $modules) {
   63   // Early return if search is not installed or if we're uninstalling this
   64   // module.
   65   if (!\Drupal::hasService('plugin.manager.search') ||
   66     in_array('help_topics', $modules)) {
   67     return;
   68   }
   69   $search_plugin_manager = \Drupal::service('plugin.manager.search');
   70   if ($search_plugin_manager->hasDefinition('help_search')) {
   71     // Ensure that topics for extensions that have been uninstalled are removed.
   72     $help_search = $search_plugin_manager->createInstance('help_search');
   73     $help_search->updateTopicList();
   74   }
   75 }
   76 
   77 /**
   78  * Implements hook_themes_uninstalled().
   79  */
   80 function help_topics_themes_uninstalled(array $themes) {
   81   // Use the same code as module uninstall to ensure that theme help is removed
   82   // when a theme is uninstalled.
   83   help_topics_modules_uninstalled([]);
   84 }