protected function RegistrationAccessControlHandler::checkAccess in RNG - Events and Registrations 8.2
Same name and namespace in other branches
- 8 src/AccessControl/RegistrationAccessControlHandler.php \Drupal\rng\AccessControl\RegistrationAccessControlHandler::checkAccess()
- 3.x src/AccessControl/RegistrationAccessControlHandler.php \Drupal\rng\AccessControl\RegistrationAccessControlHandler::checkAccess()
Parameters
\Drupal\rng\Entity\RegistrationInterface $entity: A registration entity.
Overrides EntityAccessControlHandler::checkAccess
File
- src/
AccessControl/ RegistrationAccessControlHandler.php, line 54
Class
- RegistrationAccessControlHandler
- Access controller for the registration entity.
Namespace
Drupal\rng\AccessControlCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
$account = $this
->prepareUser($account);
if (in_array($operation, [
'view',
'update',
'delete',
])) {
if ($account
->hasPermission('administer rng')) {
return AccessResult::allowed()
->cachePerPermissions();
}
$event = $entity
->getEvent();
// Event access rules.
$user = User::load($account
->id());
$context_values = [
'event' => $event,
'registration' => $entity,
'user' => $user,
];
$rules = $this->eventManager
->getMeta($event)
->getRules('rng_event.register', TRUE);
foreach ($rules as $rule) {
if ($this
->ruleGrantsOperation($rule, $operation) && $rule
->evaluateConditions($context_values)) {
return AccessResult::allowed()
->cachePerUser();
}
}
}
return AccessResult::neutral();
}