function LinkWidget::flagErrors

Same name in other branches
  1. 9 core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::flagErrors()
  2. 8.9.x core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::flagErrors()
  3. 11.x 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 441

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.