You are here

function social_tour_page_attachments in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  2. 8 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  3. 8.2 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  4. 8.3 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  5. 8.4 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  6. 8.5 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  7. 8.6 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  8. 8.7 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  9. 8.8 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  10. 10.3.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  11. 10.1.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
  12. 10.2.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()

Implements hook_page_attachments().

This will add the social_tour library to all pages that have a tour enabled so we can start it automatically.

Only for users with access though.

File

modules/custom/social_tour/social_tour.module, line 101
The Social Tour module.

Code

function social_tour_page_attachments(array &$page) {
  if (!_social_tour_init()) {
    return;
  }

  // Load all of the items and match on route name.
  $route_name = \Drupal::routeMatch()
    ->getRouteName();
  $tags = \Drupal::service('social_tour.onboarding')
    ->getCacheTags($route_name);

  // If we have a tour available, and there is at least one tour tip we attach
  // our JS library that makes sure the tour pops up immediately.
  if ($tags) {
    $page['#attached']['library'][] = 'social_tour/social_tour';
    $page['#cache']['tags'] = $tags;
  }
}