LinkNotExistingInternalConstraintValidator.php
Same filename and directory in other branches
- 11.x core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php
- 10 core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php
- 9 core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php
- 8.9.x core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php
Namespace
Drupal\link\Plugin\Validation\ConstraintFile
-
core/
modules/ link/ src/ Plugin/ Validation/ Constraint/ LinkNotExistingInternalConstraintValidator.php
View source
<?php
namespace Drupal\link\Plugin\Validation\Constraint;
use Drupal\link\LinkItemInterface;
use Symfony\Component\Routing\Exception\InvalidParameterException;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
/**
* Validates the LinkNotExistingInternal constraint.
*/
class LinkNotExistingInternalConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) : void {
if (!$value instanceof LinkItemInterface) {
throw new UnexpectedValueException($value, LinkItemInterface::class);
}
if ($value->isEmpty()) {
return;
}
try {
/** @var \Drupal\Core\Url $url */
$url = $value->getUrl();
} catch (\InvalidArgumentException) {
return;
}
if ($url->isRouted()) {
$allowed = TRUE;
try {
$url->toString(TRUE);
} catch (RouteNotFoundException) {
$allowed = FALSE;
} catch (InvalidParameterException) {
$allowed = FALSE;
} catch (MissingMandatoryParametersException) {
$allowed = FALSE;
}
if (!$allowed) {
$this->context
->buildViolation($constraint->message, [
'@uri' => $value->uri,
])
->atPath('uri')
->addViolation();
}
}
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| LinkNotExistingInternalConstraintValidator | Validates the LinkNotExistingInternal constraint. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.