public function SmartIpAdminSettingsForm::validateForm in Smart IP 8.3
Same name and namespace in other branches
- 8.4 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::validateForm()
- 8.2 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::validateForm()
Form validation 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 FormBase::validateForm
File
- src/
Form/ SmartIpAdminSettingsForm.php, line 432 - Contains \Drupal\smart_ip\Form\SmartIpAdminSettingsForm.
Class
- SmartIpAdminSettingsForm
- Smart IP main admin settings page.
Namespace
Drupal\smart_ip\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $roleId => $role) {
if ($form_state
->getValue("smart_ip_debug_{$roleId}") == TRUE && $form_state
->isValueEmpty("smart_ip_test_ip_address_{$roleId}")) {
$form_state
->setErrorByName("smart_ip_test_ip_address_{$roleId}", $this
->t('Please enter the IP address to use for @role testing.', [
'@role' => $role
->get('label'),
]));
}
}
if (!empty($form['smart_ip_data_source_selection']['smart_ip_data_source']['#options']) && empty($form_state
->getValue('smart_ip_data_source'))) {
$form_state
->setErrorByName('smart_ip_data_source', $this
->t('Please select a Smart IP data source.'));
}
/** @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::VALIDATE_SETTINGS, $event);
$form = $event
->getForm();
}