You are here

public function AutobanSettingsForm::validateForm in Automatic IP ban (Autoban) 8

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/AutobanSettingsForm.php, line 153

Class

AutobanSettingsForm
Configure autoban settings for this site.

Namespace

Drupal\autoban\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $thresholds = explode("\n", $form_state
    ->getValue('autoban_thresholds'));
  foreach ($thresholds as $threshold) {
    $threshold = intval(trim($threshold));
    if (empty($threshold) || $threshold <= 0) {
      $form_state
        ->setErrorByName('autoban_thresholds', $this
        ->t('Threshold values must be a positive integer.'));
    }
  }
  $dblog_type_exclude = explode("\n", $form_state
    ->getValue('autoban_dblog_type_exclude'));
  foreach ($dblog_type_exclude as $item) {
    $item = trim($item);
    if (empty($item)) {
      $form_state
        ->setErrorByName('autoban_dblog_type_exclude', $this
        ->t('Dblog type exclude item cannot be empty.'));
    }
  }
  if ($form_state
    ->getValue('autoban_threshold_analyze') <= 0) {
    $form_state
      ->setErrorByName('autoban_threshold_analyze', $this
      ->t("Analyze's form threshold must be a positive integer."));
  }
}