function social_tour_page_attachments in Open Social 8.5
Same name and namespace in other branches
- 8.9 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.2 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.3 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.4 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.6 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.7 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 8.8 modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 10.3.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 10.0.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 10.1.x modules/custom/social_tour/social_tour.module \social_tour_page_attachments()
- 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 102 - 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_match = \Drupal::routeMatch();
$route_name = $route_match
->getRouteName();
// Check if we have a tour at the current route for the current user.
$results = \Drupal::entityQuery('tour')
->condition('routes.*.route_name', $route_name)
->execute();
// 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 (!empty($results) && ($tours = Tour::loadMultiple(array_keys($results)))) {
if (!empty($tours)) {
$page['#attached']['library'][] = 'social_tour/social_tour';
}
}
}