FormErrorHandler
class FormErrorHandler extends FormErrorHandler (View source)
Produces inline form errors.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Provides a trait for the messenger service.
Properties
| protected MessengerInterface | $messenger | The messenger. |
|
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected RendererInterface | $renderer | The renderer service. |
Methods
Handles form errors after form validation.
Loops through and displays all form errors.
Stores errors and a list of child element errors directly on each element.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a new FormErrorHandler.
Details
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
$this
handleFormErrors(array $form, FormStateInterface $form_state)
Handles form errors after form validation.
protected
displayErrorMessages(array $form, FormStateInterface $form_state)
Loops through and displays all form errors.
To disable inline form errors for an entire form set the
disable_inline_form_errors property to TRUE on the top level of the $form
array:
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:
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__construct(TranslationInterface $string_translation, RendererInterface $renderer, MessengerInterface $messenger)
Constructs a new FormErrorHandler.