You are here

public function EventRuleResetCheck::access in RNG - Events and Registrations 3.x

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

Checks that an entity is an event type.

File

src/Access/EventRuleResetCheck.php, line 38

Class

EventRuleResetCheck
Checks that an entity is an event type.

Namespace

Drupal\rng\Access

Code

public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
  $access = AccessResult::neutral();
  if ($event = $route
    ->getDefault('event')) {
    $event = $route_match
      ->getParameter($event);
    if ($event instanceof EntityInterface) {
      $event_type = $this->eventManager
        ->eventType($event
        ->getEntityTypeId(), $event
        ->bundle());
      if ($event_type) {
        $event_meta = $this->eventManager
          ->getMeta($event);

        // Allow custom rules |OR|
        // If not default rules, then allow event manager to reset back.
        if ($event_type
          ->getAllowCustomRules() || !$event_meta
          ->isDefaultRules('rng_event.register')) {
          $access = AccessResult::allowed();
        }
        $access
          ->addCacheableDependency($event_type);
      }
    }
    $access
      ->addCacheableDependency($event);
  }
  return $access;
}