public function LinkAccessConstraintValidator::validate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/link/src/Plugin/Validation/Constraint/LinkAccessConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate()
Checks if the passed value is valid.
Parameters
mixed $value The value that should be validated:
Constraint $constraint The constraint for the validation:
Overrides ConstraintValidatorInterface::validate
File
- core/
modules/ link/ src/ Plugin/ Validation/ Constraint/ LinkAccessConstraintValidator.php, line 65 - Contains \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator.
Class
- LinkAccessConstraintValidator
- Validates the LinkAccess constraint.
Namespace
Drupal\link\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) {
if (isset($value)) {
try {
$url = $value
->getUrl();
} catch (\InvalidArgumentException $e) {
return;
}
// Disallow URLs if the current user doesn't have the 'link to any page'
// permission nor can access this URI.
$allowed = $this->current_user
->hasPermission('link to any page') || $url
->access();
if (!$allowed) {
$this->context
->addViolation($constraint->message, array(
'@uri' => $value->uri,
));
}
}
}