MessageForm::validateForm

public MessageForm::validateForm(array &$form, FormStateInterface $form_state)

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

core/modules/contact/src/MessageForm.php, line 183

Class

MessageForm
Form controller for contact message forms.

Namespace

Drupal\contact

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $message = parent::validateForm($form, $form_state);

  // Check if flood control has been activated for sending emails.
  if (!$this->currentUser()->hasPermission('administer contact forms') && (!$message->isPersonal() || !$this->currentUser()->hasPermission('administer users'))) {
    $limit = $this->config('contact.settings')->get('flood.limit');
    $interval = $this->config('contact.settings')->get('flood.interval');

    if (!$this->flood->isAllowed('contact', $limit, $interval)) {
      $form_state->setErrorByName('', $this->t('You cannot send more than %limit messages in @interval. Try again later.', array(
        '%limit' => $limit,
        '@interval' => $this->dateFormatter->formatInterval($interval),
      )));
    }
  }

  return $message;
}
doc_Drupal
2016-10-29 09:28:13
Comments
Leave a Comment

Please login to continue.