You are here

public function EasyEmailForm::validateForm in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EasyEmailForm.php \Drupal\easy_email\Form\EasyEmailForm::validateForm()

Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.

Overrides ContentEntityForm::validateForm

File

src/Form/EasyEmailForm.php, line 382

Class

EasyEmailForm
Form controller for Email edit forms.

Namespace

Drupal\easy_email\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $this
    ->setValuesFromFormState($form, $form_state);

  /** @var \Drupal\easy_email\Service\EmailHandlerInterface $email_handler */
  $email_handler = \Drupal::service('easy_email.handler');
  if (!$this
    ->isEntityTypePreview() && $email_handler
    ->duplicateExists($this->entity)) {
    $form_state
      ->setError($form, $this
      ->t('Email matching unique key already exists.'));
  }
  return parent::validateForm($form, $form_state);
}