function template_preprocess_device_geolocation_visitor_info in Smart IP 8.4
Same name and namespace in other branches
- 8.3 modules/device_geolocation/device_geolocation.module \template_preprocess_device_geolocation_visitor_info()
Prepares variables for visitor's geolocation block templates.
Default template: device-geolocation-visitor-info.html.twig.
Parameters
array $variables:
File
- modules/
device_geolocation/ device_geolocation.module, line 52 - Provides visitor's geographical location using client device location source that implements W3C Geolocation API and Google Geocoding service.
Code
function template_preprocess_device_geolocation_visitor_info(&$variables) {
$blockData = [];
foreach ($variables['location'] as $label => $value) {
if ($label == 'isEuCountry' && !$value || $label == 'isGdprCountry' && !$value || !empty($value) && $label != 'regionCode' && $label != 'originalData' && $label != 'ipVersion') {
if ($label == 'source') {
switch ($value) {
case SmartIpLocationInterface::GEOCODED_SMART_IP:
$value = t('Google Map Geocoded Smart IP coordinates');
break;
case SmartIpLocationInterface::W3C:
$value = t('Geocoded W3C coordinates');
break;
default:
$value = t('Smart IP geolocation');
break;
}
}
elseif ($label == 'isEuCountry' || $label == 'isGdprCountry') {
if ($value) {
$value = t('Yes');
}
else {
$value = t('No');
}
}
elseif ($label == 'timestamp') {
$value = \Drupal::service('date.formatter')
->format($value, 'long');
}
$label = preg_replace('/(?<=\\w)(?=[A-Z])/', " \$1", $label);
$label = str_replace('_', ' ', $label);
$label = ucwords(mb_strtolower($label));
$blockData[$label] = $value;
}
}
$variables['location'] = $blockData;
}