tour.module

You are here

Main functions of the module.

Functions

Namesort descending Description
tour_help Implements hook_help().
tour_permission Implements hook_permission().
tour_preprocess_page Implements hook_preprocess_HOOK() for page templates.
tour_toolbar Implements hook_toolbar().
tour_tour_insert Implements hook_tour_insert().
tour_tour_update Implements hook_tour_update().

File

core/modules/tour/tour.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Main functions of the module.
  5. */
  6. use Drupal\Core\Cache\CacheBackendInterface;
  7. use Symfony\Cmf\Component\Routing\RouteObjectInterface;
  8. /**
  9. * Implements hook_help().
  10. */
  11. function tour_help($path, $arg) {
  12. switch ($path) {
  13. case 'admin/help#tour':
  14. $output = '';
  15. $output .= '<h3>' . t('About') . '</h3>';
  16. $output .= '<p>' . t("The Tour module provides users with guided tours of the site interface. Each tour consists of several tips that highlight elements of the user interface, guide the user through a workflow, or explain key concepts of the website. For more information, see <a href='!tour'>the online documentation for the Tour module</a>.", array('!tour' => 'https://drupal.org/documentation/modules/tour')) . '</p>';
  17. $output .= '<h3>' . t('Uses') . '</h3>';
  18. $output .= '<dl>';
  19. $output .= '<dt>' . t('Viewing tours') . '</dt>';
  20. $output .= '<dd>' . t("If a tour is available on a page, a <em>Tour</em> button will be visible in the toolbar. If you click this button the first tip of the tour will appear. The tour continues after clicking the <em>Next</em> button in the tip. To see a tour users must have the permission <em>Access tour</em> and JavaScript must be enabled in the browser") . '</dd>';
  21. $output .= '<dt>' . t('Creating tours') . '</dt>';
  22. $output .= '<dd>' . t("Tours can be written as YAML-documents with a text editor, or using the contributed <a href='!tour_ui'>Tour UI</a> module. For more information, see <a href='!doc_url'>the online documentation for writing tours</a>.", array('!doc_url' => 'https://drupal.org/developing/api/tour', '!tour_ui' => 'https://drupal.org/project/tour_ui')) . '</dd>';
  23. $output .= '</dl>';
  24. return $output;
  25. }
  26. }
  27. /**
  28. * Implements hook_permission().
  29. */
  30. function tour_permission() {
  31. return array(
  32. 'access tour' => array(
  33. 'title' => t('Access tour'),
  34. 'description' => t('View tour tips.'),
  35. ),
  36. );
  37. }
  38. /**
  39. * Implements hook_toolbar().
  40. */
  41. function tour_toolbar() {
  42. if (!\Drupal::currentUser()->hasPermission('access tour')) {
  43. return;
  44. }
  45. $tab['tour'] = array(
  46. '#type' => 'toolbar_item',
  47. 'tab' => array(
  48. '#type' => 'html_tag',
  49. '#tag' => 'button',
  50. '#value' => t('Tour'),
  51. '#attributes' => array(
  52. 'class' => array('toolbar-icon', 'toolbar-icon-help'),
  53. 'role' => 'button',
  54. 'aria-pressed' => 'false',
  55. ),
  56. ),
  57. '#wrapper_attributes' => array(
  58. 'class' => array('tour-toolbar-tab', 'hidden'),
  59. 'id' => 'toolbar-tab-tour',
  60. ),
  61. '#attached' => array(
  62. 'library' => array(
  63. 'tour/tour',
  64. ),
  65. ),
  66. );
  67. return $tab;
  68. }
  69. /**
  70. * Implements hook_preprocess_HOOK() for page templates.
  71. */
  72. function tour_preprocess_page(&$variables) {
  73. if (!\Drupal::currentUser()->hasPermission('access tour')) {
  74. return;
  75. }
  76. // Load all of the items and match on route name.
  77. $request = \Drupal::request();
  78. $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME);
  79. $results = \Drupal::entityQuery('tour')
  80. ->condition('routes.*.route_name', $route_name)
  81. ->execute();
  82. if (!empty($results) && $tours = entity_load_multiple('tour', array_keys($results))) {
  83. foreach ($tours as $id => $tour) {
  84. // Match on params.
  85. if (!$tour->hasMatchingRoute($route_name, $request->attributes->get('_raw_variables')->all())) {
  86. unset($tours[$id]);
  87. }
  88. }
  89. if (!empty($tours)) {
  90. $variables['page']['help']['tour'] = entity_view_multiple($tours, 'full');
  91. }
  92. }
  93. }
  94. /**
  95. * Implements hook_tour_insert().
  96. */
  97. function tour_tour_insert($entity) {
  98. \Drupal::service('plugin.manager.tour.tip')->clearCachedDefinitions();
  99. }
  100. /**
  101. * Implements hook_tour_update().
  102. */
  103. function tour_tour_update($entity) {
  104. \Drupal::service('plugin.manager.tour.tip')->clearCachedDefinitions();
  105. }