protected function FormErrorHandler::displayErrorMessages

protected FormErrorHandler::displayErrorMessages(array $form, FormStateInterface $form_state)

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.

File

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

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->drupalSetMessage($error, 'error');
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormErrorHandler.php/function/FormErrorHandler::displayErrorMessages/8.1.x