You are here

public function RealnameAdminSettingsForm::validateForm in Real Name 2.x

Same name and namespace in other branches
  1. 8 src/Form/RealnameAdminSettingsForm.php \Drupal\realname\Form\RealnameAdminSettingsForm::validateForm()

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/RealnameAdminSettingsForm.php, line 66

Class

RealnameAdminSettingsForm
Configure Realname settings for this site.

Namespace

Drupal\realname\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $pattern = $form_state
    ->getValue('realname_pattern');

  // Tokens that will cause recursion.
  $tokens = [
    '[user:name]',
  ];
  foreach ($tokens as $token) {
    if (strpos($pattern, $token) !== FALSE) {
      $form_state
        ->setErrorByName('realname_pattern', $this
        ->t('The %token token cannot be used as it will cause recursion.', [
        '%token' => $token,
      ]));
    }
  }
}