By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-beta12
Issue links:
Description:
There are usecases where your entity form contains custom form elements, without fieldapi widgets.
For those you though still want to have entity validation be applied.
Therefore a new API was added.
You need two steps in order to leverage it.
Step 1: Specify which fields got changed
:
protected function getEditedFieldNames(FormStateInterface $form_state) {
return array_merge(['created', 'name'], parent::getEditedFieldNames($form_state));
}
Step 2: Apply the violations to the form elements
Note: flagViolations is called for you.
protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {
foreach ($violations->getByField('created') as $violation) {
$form_state->setErrorByName('date', $violation->getMessage());
}
}
Impacts:
Module developers