You are here

public function LinkWidget::flagErrors in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::flagErrors()

Override the '%uri' message parameter, to ensure that 'internal:' URIs show a validation error message that doesn't mention that scheme.

Overrides WidgetBase::flagErrors

File

core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php, line 350
Contains \Drupal\link\Plugin\Field\FieldWidget\LinkWidget.

Class

LinkWidget
Plugin implementation of the 'link' widget.

Namespace

Drupal\link\Plugin\Field\FieldWidget

Code

public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {

  /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
  foreach ($violations as $offset => $violation) {
    $parameters = $violation
      ->getParameters();
    if (isset($parameters['@uri'])) {
      $parameters['@uri'] = static::getUriAsDisplayableString($parameters['@uri']);
      $violations
        ->set($offset, new ConstraintViolation($this
        ->t($violation
        ->getMessageTemplate(), $parameters), $violation
        ->getMessageTemplate(), $parameters, $violation
        ->getRoot(), $violation
        ->getPropertyPath(), $violation
        ->getInvalidValue(), $violation
        ->getPlural(), $violation
        ->getCode()));
    }
  }
  parent::flagErrors($items, $violations, $form, $form_state);
}