public function SmartIpAdminSettingsForm::submitForm in Smart IP 8.2
Same name and namespace in other branches
- 8.4 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::submitForm()
- 8.3 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- src/
Form/ SmartIpAdminSettingsForm.php, line 306 - Contains \Drupal\smart_ip\Form\SmartIpAdminSettingsForm.
Class
- SmartIpAdminSettingsForm
- Smart IP main admin settings page.
Namespace
Drupal\smart_ip\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$debugMode = $form_state
->getValue('smart_ip_debug');
if ($debugMode) {
$ip = $form_state
->getValue('smart_ip_test_ip_address');
$type = $this
->t('debug');
}
else {
$ip = \Drupal::request()
->getClientIp();
$type = $this
->t('actual');
}
$location = \Drupal\smart_ip\SmartIp::query($ip);
if (isset($location['latitude']) && isset($location['longitude'])) {
drupal_set_message($this
->t('Using @type IP: %ip / Country: %country / Region: %region / City: %city / Postal code: %zip / Longitude: %long / Latitude: %lat / Time zone: %time_zone', array(
'@type' => $type,
'%ip' => $location['ipAddress'],
'%country' => $location['country'],
'%region' => $location['region'],
'%city' => $location['city'],
'%zip' => $location['zip'],
'%long' => $location['longitude'],
'%lat' => $location['latitude'],
'%time_zone' => $location['timeZone'],
)));
}
\Drupal::service('smart_ip.smart_ip_location')
->save();
$this
->config('smart_ip.settings')
->set('data_source', $form_state
->getValue('smart_ip_data_source'))
->set('roles_to_geolocate', $form_state
->getValue('smart_ip_roles_to_geolocate'))
->set('save_user_location_creation', $form_state
->getValue('smart_ip_save_user_location_creation'))
->set('debug_mode', $debugMode)
->set('debug_mode_ip', $form_state
->getValue('smart_ip_test_ip_address'))
->set('allowed_pages', $form_state
->getValue('smart_ip_allowed_pages'))
->save();
/** @var \Drupal\smart_ip\AdminSettingsEvent $event */
$event = \Drupal::service('smart_ip.admin_settings_event');
// Allow Smart IP source module to add validation on their form elements
$event
->setForm($form);
$event
->setFormState($form_state);
\Drupal::service('event_dispatcher')
->dispatch(SmartIpEvents::SUBMIT_SETTINGS, $event);
$form = $event
->getForm();
}