public function EntityFormDisplay::flagWidgetsErrorsFromViolations in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::flagWidgetsErrorsFromViolations()
- 9 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::flagWidgetsErrorsFromViolations()
Flags entity validation violations as form errors.
This method processes all violations passed, thus any violations not related to fields of the form display must be processed before this method is invoked.
The method flags constraint violations related to fields shown on the form as form errors on the correct form elements. Possibly pre-existing violations of hidden fields (so fields not appearing in the display) are ignored. Other, non-field related violations are passed through and set as form errors according to the property path of the violations.
Parameters
\Drupal\Core\Entity\EntityConstraintViolationListInterface $violations: The violations to flag.
array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Overrides EntityFormDisplayInterface::flagWidgetsErrorsFromViolations
1 call to EntityFormDisplay::flagWidgetsErrorsFromViolations()
- EntityFormDisplay::validateFormValues in core/
lib/ Drupal/ Core/ Entity/ Entity/ EntityFormDisplay.php - Validates submitted widget values and sets the corresponding form errors.
File
- core/
lib/ Drupal/ Core/ Entity/ Entity/ EntityFormDisplay.php, line 261
Class
- EntityFormDisplay
- Configuration entity that contains widget options for all components of an entity form in a given form mode.
Namespace
Drupal\Core\Entity\EntityCode
public function flagWidgetsErrorsFromViolations(EntityConstraintViolationListInterface $violations, array &$form, FormStateInterface $form_state) {
$entity = $violations
->getEntity();
foreach ($violations
->getFieldNames() as $field_name) {
// Only show violations for fields that actually appear in the form, and
// let the widget assign the violations to the correct form elements.
if ($widget = $this
->getRenderer($field_name)) {
$field_violations = $this
->movePropertyPathViolationsRelativeToField($field_name, $violations
->getByField($field_name));
$widget
->flagErrors($entity
->get($field_name), $field_violations, $form, $form_state);
}
}
}