public function TextInputWidget::flagViolations in Typed Data API enhancements 8
Reports validation errors against actual form elements.
Depending on the widget's internal structure, a property-level validation error needs to be flagged on the right sub-element.
Note that validation is run according to the validation constraints of the data definition. In addition to that, widget-level validation may be provided using the regular #element_validate callbacks of the form API.
Parameters
\Drupal\Core\TypedData\TypedDataInterface $data: The data to be edited.
\Symfony\Component\Validator\ConstraintViolationListInterface $violations: A list of constraint violations to flag.
\Drupal\Core\Form\SubformStateInterface $formState: The form state of the widget's form.
Overrides FormWidgetInterface::flagViolations
File
- src/
Plugin/ TypedDataFormWidget/ TextInputWidget.php, line 83
Class
- TextInputWidget
- Plugin implementation of the 'text_input' widget.
Namespace
Drupal\typed_data\Plugin\TypedDataFormWidgetCode
public function flagViolations(TypedDataInterface $data, ConstraintViolationListInterface $violations, SubformStateInterface $formState) {
foreach ($violations as $violation) {
/** @var ConstraintViolationInterface $violation */
$formState
->setErrorByName('value', $violation
->getMessage());
}
}