You are here

public static function EmailVerifyWidget::validateElement in Email Verify 8.2

Form validation handler for widget elements.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

File

src/Plugin/Field/FieldWidget/EmailVerifyWidget.php, line 47
Contains \Drupal\email_verifyPlugin\Field\FieldWidget\EmailVerifyWidget.

Class

EmailVerifyWidget
Plugin implementation of the 'email_default' widget.

Namespace

Drupal\email_verify\Plugin\Field\FieldWidget

Code

public static function validateElement(array $element, FormStateInterface $form_state) {
  if (isset($element['value']['#value']) && !empty($element['value']['#value'])) {
    $manager = \Drupal::getContainer()
      ->get('email_verify.manager');
    $email = $element['value']['#value'];
    $host = Unicode::substr(strstr($email, '@'), 1);
    $manager
      ->checkHost($host);

    // Only check full emails if the host can connect out on port 25.
    if (\Drupal::config('email_verify.settings')
      ->get('active')) {
      $manager
        ->checkEmail($element['value']['#value']);
    }
    if ($errors = $manager
      ->getErrors()) {
      foreach ($errors as $error) {
        $form_state
          ->setError($element, $error);
      }
    }
  }
}