class LinkNotExistingInternalConstraintValidator
Validates the LinkNotExistingInternal constraint.
Hierarchy
- class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
- class \Drupal\link\Plugin\Validation\Constraint\LinkNotExistingInternalConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of LinkNotExistingInternalConstraintValidator
File
-
core/
modules/ link/ src/ Plugin/ Validation/ Constraint/ LinkNotExistingInternalConstraintValidator.php, line 14
Namespace
Drupal\link\Plugin\Validation\ConstraintView source
class LinkNotExistingInternalConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) : void {
if (isset($value)) {
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
->addViolation($constraint->message, [
'@uri' => $value->uri,
]);
}
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ConstraintValidator::$context | protected | property | ||
ConstraintValidator::formatTypeOf | protected | function | Returns a string representation of the type of the value. | |
ConstraintValidator::formatValue | protected | function | Returns a string representation of the value. | |
ConstraintValidator::formatValues | protected | function | Returns a string representation of a list of values. | |
ConstraintValidator::initialize | public | function | Initializes the constraint validator. | Overrides ConstraintValidatorInterface::initialize |
ConstraintValidator::OBJECT_TO_STRING | public | constant | Whether to cast objects with a "__toString()" method to strings. | |
ConstraintValidator::PRETTY_DATE | public | constant | Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter} (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s"). |
|
LinkNotExistingInternalConstraintValidator::validate | public | function | Checks if the passed value is valid. | Overrides ConstraintValidatorInterface::validate |