You are here

public function AutoUsernameSettingsForm::validateForm in Automatic User Names 8

Validate auto_username_settings_form form submissions.

Overrides FormBase::validateForm

File

src/Form/AutoUsernameSettingsForm.php, line 257

Class

AutoUsernameSettingsForm
Class AutoUsernameSettingsForm.

Namespace

Drupal\auto_username\Form

Code

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

  // Perform a basic check for HTML characters in the strings to remove field.
  if (strip_tags($form_state
    ->getValue('aun_ignore_words')) != $form_state
    ->getValue('aun_ignore_words')) {
    $form_state
      ->setErrorByName('aun_ignore_words', $this
      ->t('The <em>Strings to remove</em> field must not contain HTML. Make sure to disable any WYSIWYG editors for this field.'));
  }

  // Validate that the separator is not set to be removed.
  // This isn't really all that bad so warn, but still allow them to save the
  // value.
  $separator = $form_state
    ->getValue('aun_separator');
  $punctuation = $this
    ->autoUsernamePunctuationChars();
  foreach ($punctuation as $name => $details) {
    if ($details['value'] == $separator) {
      $action = $form_state
        ->getValue('aun_punctuation_' . $name);
      if ($action == AUN_PUNCTUATION_REMOVE) {
        drupal_set_message($this
          ->t('You have configured the @name to be the separator and to be removed when encountered in strings. You should probably set the action for @name to be "replace by separator".', [
          '@name' => $details['name'],
        ]), 'error');
      }
    }
  }
}