You are here

public function DatetimeRangeWidget::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/DatetimeRangeWidget.php, line 104

Class

DatetimeRangeWidget
Plugin implementation of the 'datetime_range' widget.

Namespace

Drupal\typed_data\Plugin\TypedDataFormWidget

Code

public function flagViolations(TypedDataInterface $data, ConstraintViolationListInterface $violations, SubformStateInterface $formState) {
  foreach ($violations as $violation) {

    /** @var ConstraintViolationInterface $violation */
    $formState
      ->setErrorByName('value', $violation
      ->getMessage());
  }
}