class OwnOrAdminConstraintValidator in Simple OAuth (OAuth2) & OpenID Connect 8
Class OwnOrAdminConstraintValidator.
@package Drupal\simple_oauth\Plugin\Validation\Constraint
Hierarchy
- class \Drupal\simple_oauth\Plugin\Validation\Constraint\OwnOrAdminConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of OwnOrAdminConstraintValidator
1 file declares its use of OwnOrAdminConstraintValidator
- OwnOrAdminConstraintValidatorTest.php in tests/
src/ Unit/ Plugin/ Validation/ Constraint/ OwnOrAdminConstraintValidatorTest.php
File
- src/
Plugin/ Validation/ Constraint/ OwnOrAdminConstraintValidator.php, line 13
Namespace
Drupal\simple_oauth\Plugin\Validation\ConstraintView source
class OwnOrAdminConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
/* @var OwnOrAdminConstraintInterface $constraint */
$account = $constraint
->getAccount();
if ($value == $account
->id()) {
// No violation if the user is the same as the provided one.
return NULL;
}
if ($account
->hasPermission($constraint
->getPermission())) {
// No violation if the current user has admin rights.
return NULL;
}
$this->context
->addViolation($constraint->message, [
'@permission' => $constraint
->getPermission(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OwnOrAdminConstraintValidator:: |
public | function | Checks if the passed value is valid. |