opigno_tour.module in Opigno tour 8
Same filename and directory in other branches
Contains opigno_tour.module.
File
opigno_tour.moduleView source
<?php
/**
* @file
* Contains opigno_tour.module.
*/
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Url;
use Drupal\opigno_tour\OpignoTourFunctions;
/**
* Implements hook_preprocess_page().
*/
function opigno_tour_preprocess_page(&$variables) {
$route_name = \Drupal::routeMatch()
->getRouteName();
if (OpignoTourFunctions::checkRouteTour($route_name)) {
$uid = $variables['user']
->id();
$tour = \Drupal::request()->query
->get('tour');
$viewed = OpignoTourFunctions::isPageUserViewed($route_name, $uid);
if (!$viewed) {
// If user firstly viewing current page(route).
// Save user viewed current page(route).
OpignoTourFunctions::savePageUserViewed($route_name, $uid);
// Merge route params.
$params = \Drupal::routeMatch()
->getRawParameters()
->all();
if ($tour) {
return;
}
$params = array_merge($params, [
'tour' => 1,
]);
// Reload page with "tour=1" parameter.
$url = Url::fromRoute($route_name, $params, [
'absolute' => TRUE,
]);
$response = new RedirectResponse($url
->toString());
$response
->send();
return;
}
}
}
/**
* Adds Tour popup styling.
*
* Implements hook_page_attachments().
*/
function opigno_tour_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'opigno_tour/tour_styling';
}
Functions
Name | Description |
---|---|
opigno_tour_page_attachments | Adds Tour popup styling. |
opigno_tour_preprocess_page | Implements hook_preprocess_page(). |