function LinkAccessConstraintValidator::validate
Same name in other branches
- 9 core/modules/link/src/Plugin/Validation/Constraint/LinkAccessConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate()
- 8.9.x core/modules/link/src/Plugin/Validation/Constraint/LinkAccessConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate()
- 10 core/modules/link/src/Plugin/Validation/Constraint/LinkAccessConstraintValidator.php \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate()
File
-
core/
modules/ link/ src/ Plugin/ Validation/ Constraint/ LinkAccessConstraintValidator.php, line 46
Class
- LinkAccessConstraintValidator
- Validates the LinkAccess constraint.
Namespace
Drupal\link\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) : void {
if (isset($value)) {
try {
$url = $value->getUrl();
} catch (\InvalidArgumentException) {
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, [
'@uri' => $value->uri,
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.