You are here

public function AddWordsForm::validateForm in Restrict Abusive Words 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/AddWordsForm.php, line 56
Contains \Drupal\restrict_abusive_words\Form\AdminSettingForm.

Class

AddWordsForm
Contribute form.

Namespace

Drupal\restrict_abusive_words\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $words_list = explode("\n", $form_state
    ->getValue('words_list'));
  $words = array_filter(array_map('trim', $words_list), 'strlen');
  foreach ($words as $word) {
    $search_string = _restrict_abusive_words_get_words_list();
    $check_word = _restrict_abusive_words_exists_words($search_string, $word);
    if ($check_word) {
      $form_state
        ->setErrorByName('words_list', t('@word is already exist', array(
        '@word' => $word,
      )));
    }
  }
}