You are here

public function RegistrationAddAccessCheck::access in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Access/RegistrationAddAccessCheck.php \Drupal\rng\Access\RegistrationAddAccessCheck::access()
  2. 3.x src/Access/RegistrationAddAccessCheck.php \Drupal\rng\Access\RegistrationAddAccessCheck::access()

Checks new registrations are permitted on an event.

File

src/Access/RegistrationAddAccessCheck.php, line 38

Class

RegistrationAddAccessCheck
Checks new registrations are permitted on an event.

Namespace

Drupal\rng\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, RegistrationTypeInterface $registration_type = NULL) {
  if ($event = $route
    ->getDefault('event')) {
    $context = [
      'event' => $route_match
        ->getParameter($event),
    ];
    $access_control_handler = $this->entityManager
      ->getAccessControlHandler('registration');
    if ($registration_type) {
      return $access_control_handler
        ->createAccess($registration_type
        ->id(), $account, $context, TRUE);
    }
    else {
      return $access_control_handler
        ->createAccess(NULL, $account, $context, TRUE);
    }
  }
  return AccessResult::forbidden();
}