function opigno_tour_preprocess_page in Opigno tour 3.x
Same name and namespace in other branches
- 8 opigno_tour.module \opigno_tour_preprocess_page()
Implements hook_preprocess_page().
File
- ./
opigno_tour.module, line 15 - Contains opigno_tour.module.
Code
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;
}
}
}