/** * {@inheritdoc} */ protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) { // Manually flag violations of fields not handled by the form display. This // is necessary as entity form displays only flag violations for fields // contained in the display. $field_names = array('label', 'machine_name'); foreach ($violations->getByFields($field_names) as $violation) { list($field_name) = explode('.', $violation->getPropertyPath(), 2); $form_state->setErrorByName($field_name, $violation->getMessage()); } parent::flagViolations($violations, $form, $form_state); }
/** * {@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); }