You are here

EventAccessControlHandler.php in RNG - Events and Registrations 8.2

File

src/AccessControl/EventAccessControlHandler.php
View source
<?php

namespace Drupal\rng\AccessControl;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\rng\Entity\RuleInterface;

/**
 * Access controller for the rules and rule components.
 */
class EventAccessControlHandler extends EntityAccessControlHandler {

  /**
   * {@inheritdoc}
   */
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    $account = $this
      ->prepareUser($account);
    $child = $entity instanceof RuleInterface ? $entity : $entity
      ->getRule();
    if ($child instanceof EntityInterface) {

      /** @var $child RuleInterface|\Drupal\rng\Entity\RuleComponentInterface */
      return $child
        ->getEvent()
        ->access('manage event', $account, TRUE);
    }
    return AccessResult::neutral();
  }

}

Classes

Namesort descending Description
EventAccessControlHandler Access controller for the rules and rule components.