You are here

public function InviteSettingsForm::elementValidateEmail in User External Invite 8

Same name and namespace in other branches
  1. 2.0.x src/Form/InviteSettingsForm.php \Drupal\user_external_invite\Form\InviteSettingsForm::elementValidateEmail()

Validation handler to check that a string is a valid email address.

Parameters

$element:

\Drupal\Core\Form\FormStateInterface $form_state:

$complete_form:

File

src/Form/InviteSettingsForm.php, line 238

Class

InviteSettingsForm

Namespace

Drupal\user_external_invite\Form

Code

public function elementValidateEmail(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = $form_state
    ->getValue($element['#name']);
  if ($value !== '' && !\Drupal::service('email.validator')
    ->isValid($value)) {
    $form_state
      ->setErrorByName($element['#name'], $this
      ->t('@mail needs to be a valid email address.', [
      '@mail' => $value,
    ]));
  }
}