protected function FormErrorHandler::setElementErrorsFromFormState in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Form/FormErrorHandler.php \Drupal\Core\Form\FormErrorHandler::setElementErrorsFromFormState()
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.
1 call to FormErrorHandler::setElementErrorsFromFormState()
- FormErrorHandler::handleFormErrors in core/
lib/ Drupal/ Core/ Form/ FormErrorHandler.php - Handles form errors after form validation.
File
- core/
lib/ Drupal/ Core/ Form/ FormErrorHandler.php, line 61 - Contains \Drupal\Core\Form\FormErrorHandler.
Class
- FormErrorHandler
- Handles form errors.
Namespace
Drupal\Core\FormCode
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);
}