You are here

public function SmartIpAdminSettingsForm::validateForm in Smart IP 8.2

Same name and namespace in other branches
  1. 8.4 src/Form/SmartIpAdminSettingsForm.php \Drupal\smart_ip\Form\SmartIpAdminSettingsForm::validateForm()
  2. 8.3 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 287
Contains \Drupal\smart_ip\Form\SmartIpAdminSettingsForm.

Class

SmartIpAdminSettingsForm
Smart IP main admin settings page.

Namespace

Drupal\smart_ip\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('smart_ip_debug') == TRUE && $form_state
    ->isValueEmpty('smart_ip_test_ip_address')) {
    $form_state
      ->setErrorByName('smart_ip_test_ip_address', $this
      ->t('Please enter the IP address to use for testing.'));
  }
  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();
}