You are here

public function LoginSettingsForm::validateForm in Restrict Login or Role Access by IP Address 8.4

@todo Add validation that error page is an internal path.

Overrides FormBase::validateForm

File

src/Form/LoginSettingsForm.php, line 78

Class

LoginSettingsForm
Class LoginSettingsForm.

Namespace

Drupal\restrict_by_ip\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  if (strlen($form_state
    ->getValue('restrict_by_ip_login_range')) > 0) {
    $ip_addresses = explode(";", $form_state
      ->getValue('restrict_by_ip_login_range'));
    foreach ($ip_addresses as $ip) {
      try {
        $this->ip_tools
          ->validateIP($ip);
      } catch (InvalidIPException $e) {
        $form_state
          ->setErrorByName('restrict_by_ip_login_range', $this
          ->t($e
          ->getMessage() . ' @ip.', [
          '@ip' => $ip,
        ]));
      }
    }
  }
}