You are here

public function NodeTabForm::validateTestAddress in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/NodeTabForm.php \Drupal\simplenews\Form\NodeTabForm::validateTestAddress()
  2. 8 src/Form/NodeTabForm.php \Drupal\simplenews\Form\NodeTabForm::validateTestAddress()

Validates the test address.

Parameters

array $form: An associative array containing the structure of the form.

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

File

src/Form/NodeTabForm.php, line 184

Class

NodeTabForm
Configure simplenews subscriptions of a user.

Namespace

Drupal\simplenews\Form

Code

public function validateTestAddress(array $form, FormStateInterface $form_state) {
  $test_address = $form_state
    ->getValue('test_address');
  $test_address = trim($test_address);
  if (!empty($test_address)) {
    $mails = explode(',', $test_address);
    foreach ($mails as $mail) {
      $mail = trim($mail);
      if (!$this->emailValidator
        ->isValid($mail)) {
        $form_state
          ->setErrorByName('test_address', $this
          ->t('Invalid email address "%mail".', [
          '%mail' => $mail,
        ]));
      }
    }
    $form_state
      ->set('test_addresses', $mails);
  }
  else {
    $form_state
      ->setErrorByName('test_address', $this
      ->t('Missing test email address.'));
  }
}