class LinkNotExistingInternalConstraintValidator

Same name in other branches
  1. 8.9.x core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator
  2. 10 core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator
  3. 11.x core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator

Validates the LinkNotExistingInternal constraint.

Hierarchy

Expanded class hierarchy of LinkNotExistingInternalConstraintValidator

1 file declares its use of LinkNotExistingInternalConstraintValidator
LinkNotExistingInternalConstraintValidatorTest.php in core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidatorTest.php

File

core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php, line 14

Namespace

Drupal\link\Plugin\Validation\Constraint
View source
class LinkNotExistingInternalConstraintValidator extends ConstraintValidator {
    
    /**
     * {@inheritdoc}
     */
    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(TRUE);
                } catch (RouteNotFoundException $e) {
                    $allowed = FALSE;
                } catch (InvalidParameterException $e) {
                    $allowed = FALSE;
                } catch (MissingMandatoryParametersException $e) {
                    $allowed = FALSE;
                }
                if (!$allowed) {
                    $this->context
                        ->addViolation($constraint->message, [
                        '@uri' => $value->uri,
                    ]);
                }
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
LinkNotExistingInternalConstraintValidator::validate public function

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