Verified Commit 6165e035 authored by godotislate's avatar godotislate
Browse files

task: #3262935 Link field validation constraints don't give enough detail

By: joachim
By: andregp
By: larowlan
By: sophiavs
By: alexpott
By: mohit_aghera
By: smustgrave
By: quietone
By: harshitthakore
By: murilohp
By: benjifisher
By: Tauany Bueno
By: dcam
By: rkoller
By: simohell
By: pallavi singh3013
By: godotislate
parent f2cee08d
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class LinkAccessConstraint extends SymfonyConstraint {
  #[HasNamedArguments]
  public function __construct(
    mixed $options = NULL,
    public string $message = "The path '@uri' is inaccessible.",
    public string $message = "The URL '@uri' is inaccessible.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class LinkExternalProtocolsConstraint extends SymfonyConstraint {
  #[HasNamedArguments]
  public function __construct(
    mixed $options = NULL,
    public string $message = "The path '@uri' is invalid.",
    public string $message = "The URL '@uri' has an invalid protocol.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
+10 −1
Original line number Diff line number Diff line
@@ -19,10 +19,19 @@ class LinkNotExistingInternalConstraint extends SymfonyConstraint {
  #[HasNamedArguments]
  public function __construct(
    mixed $options = NULL,
    public string $message = "The path '@uri' is invalid.",
    public string $message = '',
    public string $notFoundMessage = "The URL '@uri' doesn't exist.",
    public string $invalidParameterMessage = "The URL '@uri' has an invalid parameter.",
    public string $missingParameterMessage = "The URL '@uri' is missing a required parameter.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    if ($message !== '') {
      @trigger_error('Passing the $message argument to ' . __METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use the $notFoundMessage argument instead. See https://www.drupal.org/node/3614626', E_USER_DEPRECATED);
      if ($this->notFoundMessage === "The URL '@uri' doesn't exist.") {
        $this->notFoundMessage = $message;
      }
    }
    parent::__construct($options, $groups, $payload);
  }

+7 −7
Original line number Diff line number Diff line
@@ -36,23 +36,23 @@ public function validate($value, Constraint $constraint): void {
    }

    if ($url->isRouted()) {
      $allowed = TRUE;
      try {
        $url->toString(TRUE);
      }
      // The following exceptions are all possible during URL generation, and
      // should be considered as disallowed URLs.
      catch (RouteNotFoundException) {
        $allowed = FALSE;
        $this->context->buildViolation($constraint->notFoundMessage, ['@uri' => $value->uri])
          ->atPath('uri')
          ->addViolation();
      }
      catch (InvalidParameterException) {
        $allowed = FALSE;
        $this->context->buildViolation($constraint->invalidParameterMessage, ['@uri' => $value->uri])
          ->atPath('uri')
          ->addViolation();
      }
      catch (MissingMandatoryParametersException) {
        $allowed = FALSE;
      }
      if (!$allowed) {
        $this->context->buildViolation($constraint->message, ['@uri' => $value->uri])
        $this->context->buildViolation($constraint->missingParameterMessage, ['@uri' => $value->uri])
          ->atPath('uri')
          ->addViolation();
      }
+10 −1
Original line number Diff line number Diff line
@@ -19,10 +19,19 @@ class LinkTypeConstraint extends SymfonyConstraint {
  #[HasNamedArguments]
  public function __construct(
    mixed $options = NULL,
    public string $message = "The path '@uri' is invalid.",
    public string $message = '',
    public string $invalidMessage = "The URL '@uri' is invalid.",
    public string $onlyInternalMessage = "The URL '@uri' is external, but the @field-label field only supports internal paths.",
    public string $onlyExternalMessage = "The URL '@uri' is internal, but the @field-label field only supports external URLs.",
    ?array $groups = NULL,
    mixed $payload = NULL,
  ) {
    if ($message !== '') {
      @trigger_error('Passing the $message argument to ' . __METHOD__ . '() is deprecated in drupal:11.5.0 and is removed from drupal:12.0.0. Use the $invalidMessage argument instead. See https://www.drupal.org/node/3614626', E_USER_DEPRECATED);
      if ($this->invalidMessage === "The URL '@uri' doesn't exist.") {
        $this->invalidMessage = $message;
      }
    }
    parent::__construct($options, $groups, $payload);
  }

Loading