protected FormErrorHandler::setElementErrorsFromFormState(array &$elements, FormStateInterface &$form_state)
Stores the errors of each element directly on the element.
We must provide a way for non-form functions to check the errors for a specific element. The most common usage of this is a #pre_render callback.
Parameters
array $elements: An associative array containing the structure of a form element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- core/lib/Drupal/Core/Form/FormErrorHandler.php, line 56
Class
- FormErrorHandler
- Handles form errors.
Namespace
Drupal\Core\Form
Code
1 2 3 4 5 6 7 8 9 10 11 | protected function setElementErrorsFromFormState( array & $elements , FormStateInterface & $form_state ) { // Recurse through all children. foreach (Element::children( $elements ) as $key ) { if (isset( $elements [ $key ]) && $elements [ $key ]) { $this ->setElementErrorsFromFormState( $elements [ $key ], $form_state ); } } // Store the errors for this element on the element directly. $elements [ '#errors' ] = $form_state ->getError( $elements ); } |
Please login to continue.