You are here

class EventRuleResetCheck in RNG - Events and Registrations 8

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

Checks that an entity is an event type.

Hierarchy

Expanded class hierarchy of EventRuleResetCheck

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

File

src/Access/EventRuleResetCheck.php, line 16

Namespace

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

  /**
   * The RNG event manager.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $eventManager;

  /**
   * Constructs a new EventRuleResetCheck object.
   *
   * @param \Drupal\rng\EventManagerInterface $event_manager
   *   The RNG event manager.
   */
  public function __construct(EventManagerInterface $event_manager) {
    $this->eventManager = $event_manager;
  }

  /**
   * Checks that an entity is an event type.
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventRuleResetCheck::$eventManager protected property The RNG event manager.
EventRuleResetCheck::access public function Checks that an entity is an event type.
EventRuleResetCheck::__construct public function Constructs a new EventRuleResetCheck object.