function MessageForm::validateForm

Same name in other branches
  1. 9 core/modules/contact/src/MessageForm.php \Drupal\contact\MessageForm::validateForm()
  2. 8.9.x core/modules/contact/src/MessageForm.php \Drupal\contact\MessageForm::validateForm()
  3. 10 core/modules/contact/src/MessageForm.php \Drupal\contact\MessageForm::validateForm()

Overrides ContentEntityForm::validateForm

File

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

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.', [
                '%limit' => $limit,
                '@interval' => $this->dateFormatter
                    ->formatInterval($interval),
            ]));
        }
    }
    return $message;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.