class LinkNotExistingInternalConstraintValidator in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/link/src/Plugin/Validation/Constraint/LinkNotExistingInternalConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator
Validates the LinkNotExistingInternal constraint.
Hierarchy
- class \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator implements ConstraintValidatorInterface
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 - Contains \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidatorTest.
File
- core/
modules/ link/ src/ Plugin/ Validation/ Constraint/ LinkNotExistingInternalConstraintValidator.php, line 20 - Contains \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator.
Namespace
Drupal\link\Plugin\Validation\ConstraintView source
class LinkNotExistingInternalConstraintValidator implements ConstraintValidatorInterface {
/**
* Stores the validator's state during validation.
*
* @var \Symfony\Component\Validator\ExecutionContextInterface
*/
protected $context;
/**
* {@inheritdoc}
*/
public function initialize(ExecutionContextInterface $context) {
$this->context = $context;
}
/**
* {@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();
} 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,
));
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LinkNotExistingInternalConstraintValidator:: |
protected | property | Stores the validator's state during validation. | |
LinkNotExistingInternalConstraintValidator:: |
public | function |
Initializes the constraint validator. Overrides ConstraintValidatorInterface:: |
|
LinkNotExistingInternalConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides ConstraintValidatorInterface:: |