You are here

protected function RegistrationAccessControlHandler::checkAccess in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/AccessControl/RegistrationAccessControlHandler.php \Drupal\rng\AccessControl\RegistrationAccessControlHandler::checkAccess()
  2. 3.x src/AccessControl/RegistrationAccessControlHandler.php \Drupal\rng\AccessControl\RegistrationAccessControlHandler::checkAccess()

Parameters

\Drupal\rng\RegistrationInterface $entity: A registration entity.

Overrides EntityAccessControlHandler::checkAccess

File

src/AccessControl/RegistrationAccessControlHandler.php, line 44

Class

RegistrationAccessControlHandler
Access controller for the registration entity.

Namespace

Drupal\rng\AccessControl

Code

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();
}