You are here

public function IpGeoLocGlobal::reinitLocation in IP Geolocation Views & Maps 8

Reinitialises the supplied location array.

File

src/Services/IpGeoLocGlobal.php, line 69

Class

IpGeoLocGlobal
Class IpGeoLocGlobal.

Namespace

Drupal\ip_geoloc\Services

Code

public function reinitLocation(&$location, $reverse_geocode_client_timeout) {
  $location = [
    'fixed_address' => isset($location['fixed_address']) ? (int) $location['fixed_address'] : NULL,
    'regions' => isset($location['regions']) ? $location['regions'] : NULL,
  ];

  // Calls below are synchronous, $location is filled upon return.
  if ($this
    ->useSmartIpIfEnabled($location) || $this
    ->useGeoipApiIfEnabled($location)) {
    if ($reverse_geocode_client_timeout) {
      $this->logger
        ->get('IPGV&M')
        ->notice('Location timeout (waited %sec s). Fallback: %address.', [
        '%sec' => number_format($reverse_geocode_client_timeout, 1),
        '%address' => isset($location['formatted_address']) ? $location['formatted_address'] : '',
      ], WATCHDOG_NOTICE);
    }
  }
  else {
    $this
      ->debug($this->stringTranslation
      ->translate('Smart IP and GeoIP API fallbacks NOT enabled.'));
  }
}