You are here

public function LinkNotExistingInternalConstraintValidator::validate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator::validate()

Checks if the passed value is valid.

Parameters

mixed $value The value that should be validated:

Constraint $constraint The constraint for the validation:

Overrides ConstraintValidatorInterface::validate

File

core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php, line 39
Contains \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator.

Class

LinkNotExistingInternalConstraintValidator
Validates the LinkNotExistingInternal constraint.

Namespace

Drupal\link\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  if (isset($value)) {
    try {

      /** @var \Drupal\Core\Url $url */
      $url = $value
        ->getUrl();
    } catch (\InvalidArgumentException $e) {
      return;
    }
    if ($url
      ->isRouted()) {
      $allowed = TRUE;
      try {
        $url
          ->toString();
      } catch (RouteNotFoundException $e) {
        $allowed = FALSE;
      } catch (InvalidParameterException $e) {
        $allowed = FALSE;
      } catch (MissingMandatoryParametersException $e) {
        $allowed = FALSE;
      }
      if (!$allowed) {
        $this->context
          ->addViolation($constraint->message, array(
          '@uri' => $value->uri,
        ));
      }
    }
  }
}