class FormErrorHandler implements FormErrorHandlerInterface (View source)

Handles form errors.

Traits

Provides a trait for the messenger service.

Properties

protected MessengerInterface $messenger

The messenger.

from  MessengerTrait

Methods

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

$this
handleFormErrors(array $form, FormStateInterface $form_state)

Handles form errors after form validation.

displayErrorMessages(array $form, FormStateInterface $form_state)

Loops through and displays all form errors.

setElementErrorsFromFormState(array $form, FormStateInterface $form_state, array $elements = [])

Stores errors and a list of child element errors directly on each element.

Details

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

$this handleFormErrors(array $form, FormStateInterface $form_state)

Handles form errors after form validation.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

Return Value

$this

protected 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.

FormStateInterface $form_state

The current state of the form.

protected setElementErrorsFromFormState(array $form, FormStateInterface $form_state, array $elements = [])

Stores errors and a list of child element errors directly on each element.

Grouping elements like containers, details, fieldgroups and fieldsets may need error info from their child elements to be able to accessibly show form error messages to a user. For example, a details element should be opened when child elements have errors.

Grouping example: Assume you have a 'street' element somewhere in a form, which is displayed in a details element 'address'. It might be:

Parameters

array $form

An associative array containing a reference to the complete structure of the form.

FormStateInterface $form_state

The current state of the form.

array $elements

An associative array containing the part of the form structure that will be processed while traversing up the tree. For recursion only; leave empty when calling this method.