You are here

public function MailingListForm::validateForm in Mailing List 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

src/Form/MailingListForm.php, line 198

Class

MailingListForm
Form handler for mailing list forms.

Namespace

Drupal\mailing_list\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);
  $id = trim($form_state
    ->getValue('id'));

  // '0' is invalid, to safe empty check.
  if ($id == '0') {
    $form_state
      ->setErrorByName('id', $this
      ->t("Invalid machine-readable name. Enter a name other than %invalid.", [
      '%invalid' => $id,
    ]));
  }
  $max_per_user = intval($form_state
    ->getValue('max_per_user'));
  if ($max_per_user < 0) {
    $form_state
      ->setErrorByName('max_per_user', $this
      ->t("Limit per user must be an number greater or equal than 0."));
  }
  $max_per_email = intval($form_state
    ->getValue('max_per_email'));
  if ($max_per_email < 0) {
    $form_state
      ->setErrorByName('max_per_email', $this
      ->t("Limit per email must be an number greater or equal than 0."));
  }
}