You are here

private function DisclaimerEmailMatchForm::validateEmail in Disclaimer 8

1 call to DisclaimerEmailMatchForm::validateEmail()
DisclaimerEmailMatchForm::validateForm in src/Form/DisclaimerEmailMatchForm.php
Form validation handler.

File

src/Form/DisclaimerEmailMatchForm.php, line 173

Class

DisclaimerEmailMatchForm
Class DisclaimerEmailMatchForm.

Namespace

Drupal\disclaimer\Form

Code

private function validateEmail(array $form, FormStateInterface $form_state) {

  // Reject address in case we don't have required config.
  $this
    ->populateSettings($form, $form_state);
  if (!isset($this->blockSettings['allowed_emails'])) {
    return FALSE;
  }

  // Explode and trim spaces and line breaks.
  $allowed_emails = array_map('trim', explode("\n", $this->blockSettings['allowed_emails']));

  // Check email against the list.
  $provided_email = $form_state
    ->getValue('email');
  foreach ($allowed_emails as $allowed_email) {
    if (fnmatch($allowed_email, $provided_email, FNM_CASEFOLD)) {
      return TRUE;
    }
  }
  return FALSE;
}