You are here

public function MandrillActivityForm::validateForm in Mandrill 8

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

modules/mandrill_activity/src/Form/MandrillActivityForm.php, line 175
Contains \Drupal\mandrill_activity\Form\MandrillActivityForm.

Class

MandrillActivityForm
Form controller for the MandrillActivity entity edit form.

Namespace

Drupal\mandrill_activity\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->isSubmitted()) {
    $entity = $this->entityTypeManager
      ->getStorage('mandrill_activity')
      ->getQuery()
      ->condition('entity_type', $form_state
      ->getValue('entity_type'))
      ->condition('bundle', $form_state
      ->getValue('bundle'))
      ->execute();
    if (!empty($entity)) {
      $form_state
        ->setErrorByName('bundle', $this
        ->t('A Mandrill Activity Entity already exists for this Bundle.'));
    }
  }
}