You are here

public function NodeTabForm::validateTestAddress in Simplenews 8

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

Validates the test address.

File

src/Form/NodeTabForm.php, line 244

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 (!valid_email_address($mail)) {
        $form_state
          ->setErrorByName('test_address', t('Invalid email address "%mail".', array(
          '%mail' => $mail,
        )));
      }
    }
    $form_state
      ->set('test_addresses', $mails);
  }
  else {
    $form_state
      ->setErrorByName('test_address', t('Missing test email address.'));
  }
}