help.module 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Manages displaying online help.
  5. */
  6. use Drupal\Core\Url;
  7. use Drupal\Core\Block\BlockPluginInterface;
  8. use Drupal\Core\Routing\RouteMatchInterface;
  9. /**
  10. * Implements hook_help().
  11. */
  12. function help_help($route_name, RouteMatchInterface $route_match) {
  13. switch ($route_name) {
  14. case 'help.main':
  15. $output = '<h2>' . t('Getting Started') . '</h2>';
  16. $output .= '<p>' . t('Follow these steps to set up and start using your website:') . '</p>';
  17. $output .= '<ol>';
  18. $output .= '<li>' . t('<strong>Configure your website</strong> Once logged in, visit the <a href=":admin">Administration page</a>, where you may <a href=":config">customize and configure</a> all aspects of your website.', [':admin' => Url::fromRoute('system.admin')->toString(), ':config' => Url::fromRoute('system.admin_config')->toString()]) . '</li>';
  19. $output .= '<li>' . t('<strong>Enable additional functionality</strong> Next, visit the <a href=":modules">Extend page</a> and enable modules that suit your specific needs. You can find additional modules at the <a href=":download_modules">Drupal.org modules page</a>.', [':modules' => Url::fromRoute('system.modules_list')->toString(), ':download_modules' => 'https://www.drupal.org/project/modules']) . '</li>';
  20. $output .= '<li>' . t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href=":themes">Appearance page</a>. You may choose from one of the included themes or download additional themes from the <a href=":download_themes">Drupal.org themes page</a>.', [':themes' => Url::fromRoute('system.themes_page')->toString(), ':download_themes' => 'https://www.drupal.org/project/themes']) . '</li>';
  21. // Display a link to the create content page if Node module is enabled.
  22. if (\Drupal::moduleHandler()->moduleExists('node')) {
  23. $output .= '<li>' . t('<strong>Start posting content</strong> Finally, you may <a href=":content">add new content</a> to your website.', [':content' => Url::fromRoute('node.add_page')->toString()]) . '</li>';
  24. }
  25. $output .= '</ol>';
  26. $output .= '<p>' . t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', [':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org']) . '</p>';
  27. return ['#markup' => $output];
  28. case 'help.page.help':
  29. $output = '';
  30. $output .= '<h3>' . t('About') . '</h3>';
  31. $output .= '<p>' . t('The Help module generates <a href=":help-page">Help reference pages</a> to guide you through the use and configuration of modules, and provides a Help block with page-level help. The reference pages are a starting point for <a href=":handbook">Drupal.org online documentation</a> pages that contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the <a href=":help">online documentation for the Help module</a>.', [':help' => 'https://www.drupal.org/documentation/modules/help/', ':handbook' => 'https://www.drupal.org/documentation', ':help-page' => Url::fromRoute('help.main')->toString()]) . '</p>';
  32. $output .= '<h3>' . t('Uses') . '</h3>';
  33. $output .= '<dl>';
  34. $output .= '<dt>' . t('Providing a help reference') . '</dt>';
  35. $output .= '<dd>' . t('The Help module displays explanations for using each module listed on the main <a href=":help">Help reference page</a>.', [':help' => Url::fromRoute('help.main')->toString()]) . '</dd>';
  36. $output .= '<dt>' . t('Providing page-specific help') . '</dt>';
  37. $output .= '<dd>' . t('Page-specific help text provided by modules is displayed in the Help block. This block can be placed and configured on the <a href=":blocks">Block layout page</a>.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? Url::fromRoute('block.admin_display')->toString() : '#']) . '</dd>';
  38. $output .= '</dl>';
  39. return ['#markup' => $output];
  40. }
  41. }
  42. /**
  43. * Implements hook_theme().
  44. */
  45. function help_theme($existing, $type, $theme, $path) {
  46. return [
  47. 'help_section' => [
  48. 'variables' => [
  49. 'title' => NULL,
  50. 'description' => NULL,
  51. 'links' => NULL,
  52. 'empty' => NULL,
  53. ],
  54. ],
  55. ];
  56. }
  57. /**
  58. * Implements hook_preprocess_HOOK() for block templates.
  59. */
  60. function help_preprocess_block(&$variables) {
  61. if ($variables['plugin_id'] == 'help_block') {
  62. $variables['attributes']['role'] = 'complementary';
  63. }
  64. }
  65. /**
  66. * Implements hook_block_view_BASE_BLOCK_ID_alter().
  67. */
  68. function help_block_view_help_block_alter(array &$build, BlockPluginInterface $block) {
  69. // Assume that most users do not need or want to perform contextual actions on
  70. // the help block, so don't needlessly draw attention to it.
  71. unset($build['#contextual_links']);
  72. }