You are here

class RegistrationAddAccessCheck in RNG - Events and Registrations 8.2

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

Checks new registrations are permitted on an event.

Hierarchy

Expanded class hierarchy of RegistrationAddAccessCheck

1 string reference to 'RegistrationAddAccessCheck'
rng.services.yml in ./rng.services.yml
rng.services.yml
1 service uses RegistrationAddAccessCheck
access_check.rng.event_registrations_allowed in ./rng.services.yml
Drupal\rng\Access\RegistrationAddAccessCheck

File

src/Access/RegistrationAddAccessCheck.php, line 16

Namespace

Drupal\rng\Access
View source
class RegistrationAddAccessCheck implements AccessInterface {

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a EventRegistrationAllowedCheck object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * Checks new registrations are permitted on an event.
   */
  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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RegistrationAddAccessCheck::$entityManager protected property The entity manager.
RegistrationAddAccessCheck::access public function Checks new registrations are permitted on an event.
RegistrationAddAccessCheck::__construct public function Constructs a EventRegistrationAllowedCheck object.