You are here

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

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

Class

AutobanSettingsForm
Configure autoban settings for this site.

Namespace

Drupal\autoban\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // To ensure that the threshold values are integers.
  $thresholds = explode("\n", $form_state
    ->getValue('autoban_thresholds'));
  array_walk($thresholds, function (&$item, $key) {
    $item = (int) $item;
  });

  // To ensure that the dblog_type_exclude values was trimmed.
  $dblog_type_exclude = explode("\n", $form_state
    ->getValue('autoban_dblog_type_exclude'));
  array_walk($dblog_type_exclude, function (&$item, $key) {
    $item = trim($item);
  });
  $this->configFactory
    ->getEditable('autoban.settings')
    ->set('autoban_thresholds', implode("\n", $thresholds))
    ->set('autoban_query_mode', $form_state
    ->getValue('autoban_query_mode'))
    ->set('autoban_use_wildcards', $form_state
    ->getValue('autoban_use_wildcards'))
    ->set('autoban_whitelist', $form_state
    ->getValue('autoban_whitelist'))
    ->set('autoban_dblog_type_exclude', implode("\n", $dblog_type_exclude))
    ->set('autoban_threshold_analyze', $form_state
    ->getValue('autoban_threshold_analyze'))
    ->save();
  parent::submitForm($form, $form_state);
}