help.api.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Hooks for the Help system.
  5. */
  6. use Drupal\Core\Url;
  7. /**
  8. * @addtogroup hooks
  9. * @{
  10. */
  11. /**
  12. * Provide online user help.
  13. *
  14. * By implementing hook_help(), a module can make documentation available to
  15. * the user for the module as a whole, or for specific pages. Help for
  16. * developers should usually be provided via function header comments in the
  17. * code, or in special API example files.
  18. *
  19. * The page-specific help information provided by this hook appears in the
  20. * Help block (provided by the core Help module), if the block is displayed on
  21. * that page. The module overview help information is displayed by the Help
  22. * module. It can be accessed from the page at /admin/help or from the Extend
  23. * page. If a module implements hook_help() the help system expects module
  24. * overview help to be provided.
  25. *
  26. * For detailed usage examples of:
  27. * - Module overview help, see content_translation_help(). Module overview
  28. * help should follow
  29. * @link https://www.drupal.org/node/632280 the standard help template. @endlink
  30. * - Page-specific help using only routes, see book_help().
  31. * - Page-specific help using routes and $request, see block_help().
  32. *
  33. * @param string $route_name
  34. * For page-specific help, use the route name as identified in the
  35. * module's routing.yml file. For module overview help, the route name
  36. * will be in the form of "help.page.$modulename".
  37. * @param Drupal\Core\Routing\RouteMatchInterface $route_match
  38. * The current route match. This can be used to generate different help
  39. * output for different pages that share the same route.
  40. *
  41. * @return string|array
  42. * A render array, localized string, or object that can be rendered into
  43. * a string, containing the help text.
  44. */
  45. function hook_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
  46. switch ($route_name) {
  47. // Main module help for the block module.
  48. case 'help.page.block':
  49. return '<p>' . t('Blocks are boxes of content rendered into an area, or region, of a web page. The default theme Bartik, for example, implements the regions "Sidebar first", "Sidebar second", "Featured", "Content", "Header", "Footer", etc., and a block may appear in any one of these areas. The <a href=":blocks">blocks administration page</a> provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>';
  50. // Help for another path in the block module.
  51. case 'block.admin_display':
  52. return '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page.') . '</p>';
  53. }
  54. }
  55. /**
  56. * Perform alterations on help page section plugin definitions.
  57. *
  58. * Sections for the page at /admin/help are provided by plugins. This hook
  59. * allows modules to alter the plugin definitions.
  60. *
  61. * @param array $info
  62. * Array of plugin information exposed by hook page section plugins, altered
  63. * by reference.
  64. *
  65. * @see \Drupal\help\HelpSectionPluginInterface
  66. * @see \Drupal\help\Annotation\HelpSection
  67. * @see \Drupal\help\HelpSectionManager
  68. */
  69. function hook_help_section_info_alter(array &$info) {
  70. // Alter the header for the module overviews section.
  71. $info['hook_help']['title'] = t('Overviews of modules');
  72. // Move the module overviews section to the end.
  73. $info['hook_help']['weight'] = 500;
  74. }
  75. /**
  76. * @} End of "addtogroup hooks".
  77. */