function smart_ip_entity_insert in Smart IP 8.3
Same name and namespace in other branches
- 8.4 smart_ip.module \smart_ip_entity_insert()
- 8.2 smart_ip.module \smart_ip_entity_insert()
Implements hook_entity_insert().
Save new user's geolocation upon registration.
File
- ./
smart_ip.module, line 59 - Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address
Code
function smart_ip_entity_insert(EntityInterface $entity) {
if ($entity
->getEntityTypeId() == 'user') {
$is_new = $entity
->getCreatedTime() == \Drupal::time()
->getRequestTime();
if ($is_new) {
$save_user_location = \Drupal::config('smart_ip.settings')
->get('save_user_location_creation');
if ($save_user_location) {
$data['location'] = SmartIp::query();
// Determine if saving location details of visitor from EU countries are
// permitted.
$euVisitorsDontSave = \Drupal::config('smart_ip.settings')
->get('eu_visitor_dont_save') && $data['location']['isGdprCountry'];
if (!$euVisitorsDontSave) {
/** @var \Drupal\user\UserData $userData */
$userData = \Drupal::service('user.data');
$userData
->set('smart_ip', $entity
->id(), 'geoip_location_original', $data);
}
}
}
}
}