UpdateSettingsForm::validateForm

public UpdateSettingsForm::validateForm(array &$form, FormStateInterface $form_state)

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

core/modules/update/src/UpdateSettingsForm.php, line 105

Class

UpdateSettingsForm
Configure update settings for this site.

Namespace

Drupal\update

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $form_state->set('notify_emails', []);
  if (!$form_state->isValueEmpty('update_notify_emails')) {
    $valid = array();
    $invalid = array();
    foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
      $email = trim($email);
      if (!empty($email)) {
        if ($this->emailValidator->isValid($email)) {
          $valid[] = $email;
        }
        else {
          $invalid[] = $email;
        }
      }
    }
    if (empty($invalid)) {
      $form_state->set('notify_emails', $valid);
    }
    elseif (count($invalid) == 1) {
      $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
    }
    else {
      $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
    }
  }

  parent::validateForm($form, $form_state);
}
doc_Drupal
2016-10-29 09:51:18
Comments
Leave a Comment

Please login to continue.