3 namespace Drupal\link\Plugin\Validation\Constraint;
5 use Symfony\Component\Routing\Exception\InvalidParameterException;
6 use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
7 use Symfony\Component\Routing\Exception\RouteNotFoundException;
8 use Symfony\Component\Validator\Constraint;
9 use Symfony\Component\Validator\ConstraintValidator;
12 * Validates the LinkNotExistingInternal constraint.
14 class LinkNotExistingInternalConstraintValidator extends ConstraintValidator {
19 public function validate($value, Constraint $constraint) {
22 /** @var \Drupal\Core\Url $url */
23 $url = $value->getUrl();
25 // If the URL is malformed this constraint cannot check further.
26 catch (\InvalidArgumentException $e) {
30 if ($url->isRouted()) {
35 // The following exceptions are all possible during URL generation, and
36 // should be considered as disallowed URLs.
37 catch (RouteNotFoundException $e) {
40 catch (InvalidParameterException $e) {
43 catch (MissingMandatoryParametersException $e) {
47 $this->context->addViolation($constraint->message, ['@uri' => $value->uri]);