function mobile_device_detection_views_post_execute in Mobile Device Detection 8.3
Same name and namespace in other branches
- 8 mobile_device_detection.module \mobile_device_detection_views_post_execute()
- 8.2 mobile_device_detection.module \mobile_device_detection_views_post_execute()
Implements hook_views_post_execute().
File
- ./
mobile_device_detection.module, line 35 - Controls the visual building blocks, views a page is constructed with.
Code
function mobile_device_detection_views_post_execute(ViewExecutable $view) {
$display = $view
->getDisplay();
$extenders = $display
->getExtenders();
if (!isset($extenders['mobile_device_detection'])) {
return;
}
if (!$extenders['mobile_device_detection']
->getDevices()) {
return;
}
$devices = array_filter($extenders['mobile_device_detection']
->getDevices());
if (!empty($devices)) {
\Drupal::service('page_cache_kill_switch')
->trigger();
$view->element['#cache']['contexts'] = [
'cache_context.session',
];
$view->element['#cache']['max-age'] = 0;
$entity = \Drupal::service('mobile_device_detection.object');
$view->build_info['fail'] = TRUE;
foreach ($devices as $key => $value) {
if ($key != 'desktop') {
$func = 'is' . ucfirst($value);
if (is_callable([
$entity,
$func,
]) && $entity
->{$func}()) {
$view->build_info['fail'] = FALSE;
}
}
else {
if (!$entity
->isMobile() && !$entity
->isTablet()) {
$view->build_info['fail'] = FALSE;
}
}
}
}
}