public function BrokenWidget::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/ BrokenWidget.php, line 61
Class
- BrokenWidget
- Plugin implementation of the 'broken' widget.
Namespace
Drupal\typed_data\Plugin\TypedDataFormWidgetCode
public function flagViolations(TypedDataInterface $data, ConstraintViolationListInterface $violations, SubformStateInterface $formState) {
$formState
->setErrorByName('value', $this
->t('The field %field_label consists of the data type %data_type which cannot be input or a widget for this data type is not implemented yet.', [
'%field_label' => $this->configuration['label'] ?: $data
->getDataDefinition()
->getLabel(),
'%data_type' => $data
->getDataDefinition()
->getDataType(),
]));
}