/** * {@inheritdoc} */ protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) { // Manually flag violations of fields not handled by the form display. foreach ($violations->getByField('created') as $violation) { $form_state->setErrorByName('date', $violation->getMessage()); } foreach ($violations->getByField('name') as $violation) { $form_state->setErrorByName('name', $violation->getMessage()); } parent::flagViolations($violations, $form, $form_state); }
/** * {@inheritdoc} */ 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); } } }