function FormErrorHandler::displayErrorMessages

Loops through and displays all form errors.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

2 calls to FormErrorHandler::displayErrorMessages()
FormErrorHandler::displayErrorMessages in core/modules/inline_form_errors/src/FormErrorHandler.php
Loops through and displays all form errors.
FormErrorHandler::handleFormErrors in core/lib/Drupal/Core/Form/FormErrorHandler.php
Handles form errors after form validation.
1 method overrides FormErrorHandler::displayErrorMessages()
FormErrorHandler::displayErrorMessages in core/modules/inline_form_errors/src/FormErrorHandler.php
Loops through and displays all form errors.

File

core/lib/Drupal/Core/Form/FormErrorHandler.php, line 40

Class

FormErrorHandler
Handles form errors.

Namespace

Drupal\Core\Form

Code

protected function displayErrorMessages(array $form, FormStateInterface $form_state) {
  $errors = $form_state->getErrors();
  // Loop through all form errors and set an error message.
  foreach ($errors as $error) {
    $this->messenger()
      ->addMessage($error, 'error');
  }
}

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