public static function SmartIpAdminSettingsForm::manualLookup in Smart IP 8.3
Same name and namespace in other branches
- 8.4 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::manualLookup()
- 8.2 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::manualLookup()
Submit handler to lookup an IP address in the database.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
See also
\Drupal\smart_ip\Form\SmartIpAdminSettingsForm::manualLookupAjax
File
- src/
Form/ SmartIpAdminSettingsForm.php, line 370 - Contains \Drupal\smart_ip\Form\SmartIpAdminSettingsForm.
Class
- SmartIpAdminSettingsForm
- Smart IP main admin settings page.
Namespace
Drupal\smart_ip\FormCode
public static function manualLookup(array $form, FormStateInterface $form_state) {
$ip = $form_state
->getValue('smart_ip_lookup');
$location = SmartIp::query($ip);
if (isset($location['countryCode'])) {
$isEuCountry = $location['isEuCountry'] ? t('Yes') : t('No');
$isGdprCountry = $location['isGdprCountry'] ? t('Yes') : t('No');
$message = '<p>' . t('IP Address @ip is assigned to the following location details:', [
'@ip' => $ip,
]) . '</p>' . '<dl>' . '<dt>' . t('Country:') . '</dt>' . '<dd>' . t('%country', [
'%country' => $location['country'],
]) . '</dd>' . '<dt>' . t('Country code:') . '</dt>' . '<dd>' . t('%country_code', [
'%country_code' => $location['countryCode'],
]) . '</dd>' . '<dt>' . t('Region:') . '</dt>' . '<dd>' . t('%region', [
'%region' => $location['region'],
]) . '</dd>' . '<dt>' . t('Region code:') . '</dt>' . '<dd>' . t('%region_code', [
'%region_code' => $location['regionCode'],
]) . '</dd>' . '<dt>' . t('City:') . '</dt>' . '<dd>' . t('%city', [
'%city' => $location['city'],
]) . '</dd>' . '<dt>' . t('Postal code:') . '</dt>' . '<dd>' . t('%zip', [
'%zip' => $location['zip'],
]) . '</dd>' . '<dt>' . t('Latitude:') . '</dt>' . '<dd>' . t('%latitude', [
'%latitude' => $location['latitude'],
]) . '</dd>' . '<dt>' . t('Longitude:') . '</dt>' . '<dd>' . t('%longitude', [
'%longitude' => $location['longitude'],
]) . '</dd>' . '<dt>' . t('Is EU member country:') . '</dt>' . '<dd>' . $isEuCountry . '</dd>' . '<dt>' . t('Is GDPR country:') . '</dt>' . '<dd>' . $isGdprCountry . '</dd>' . '<dt>' . t('Time zone:') . '</dt>' . '<dd>' . t('%time_zone', [
'%time_zone' => $location['timeZone'],
]) . '</dd>' . '</dl>';
}
else {
$message = t('IP Address @ip is not assigned to any location.', [
'@ip' => $ip,
]);
}
$storage['smart_ip_message'] = $message;
$form_state
->setStorage($storage);
$form_state
->setRebuild();
}