You are here

class AccessEventBase in Organic groups 8

Base class for OG access events.

Hierarchy

Expanded class hierarchy of AccessEventBase

File

src/Event/AccessEventBase.php, line 18

Namespace

Drupal\og\Event
View source
class AccessEventBase extends Event implements AccessEventInterface {
  use RefinableCacheableDependencyTrait;

  /**
   * The access result.
   *
   * @var \Drupal\Core\Access\AccessResultInterface
   */
  protected $access;

  /**
   * The group that provides the context for the access check.
   *
   * @var \Drupal\Core\Entity\ContentEntityInterface
   */
  protected $group;

  /**
   * The user for which to check access.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $user;

  /**
   * Constructs an AccessEventBase event.
   *
   * @param \Drupal\Core\Entity\ContentEntityInterface $group
   *   The group that provides the context in which to perform the access check.
   * @param \Drupal\Core\Session\AccountInterface $user
   *   The user for which to check access.
   */
  public function __construct(ContentEntityInterface $group, AccountInterface $user) {
    $this->group = $group;
    $this->user = $user;
    $this->access = AccessResult::neutral();
  }

  /**
   * {@inheritdoc}
   */
  public function grantAccess() : AccessResultInterface {
    $this->access = $this->access
      ->orIf(AccessResult::allowed());
    return $this->access;
  }

  /**
   * {@inheritdoc}
   */
  public function denyAccess() : AccessResultInterface {
    $this->access = $this->access
      ->orIf(AccessResult::forbidden());
    return $this->access;
  }

  /**
   * {@inheritdoc}
   */
  public function mergeAccessResult(AccessResultInterface $access_result) : AccessResultInterface {
    $this->access = $this->access
      ->orIf($access_result);
    return $this->access;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroup() : ContentEntityInterface {
    return $this->group;
  }

  /**
   * {@inheritdoc}
   */
  public function getUser() : AccountInterface {
    return $this->user;
  }

  /**
   * {@inheritdoc}
   */
  public function getAccessResult() : AccessResultInterface {
    $access = $this->access;

    // Enrich the access result object with our cacheability metadata in case it
    // supports it.
    if ($access instanceof RefinableCacheableDependencyInterface) {
      $access
        ->addCacheableDependency($this);
    }
    return $access;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AccessEventBase::$access protected property The access result.
AccessEventBase::$group protected property The group that provides the context for the access check.
AccessEventBase::$user protected property The user for which to check access.
AccessEventBase::denyAccess public function Declare that access is being denied. Overrides AccessEventInterface::denyAccess
AccessEventBase::getAccessResult public function Returns the current access result object. Overrides AccessEventInterface::getAccessResult
AccessEventBase::getGroup public function Returns the group that provides the context for the access check. Overrides AccessEventInterface::getGroup
AccessEventBase::getUser public function Returns the user for which access is being determined. Overrides AccessEventInterface::getUser
AccessEventBase::grantAccess public function Declare that access is being granted. Overrides AccessEventInterface::grantAccess
AccessEventBase::mergeAccessResult public function Merges the given access result with the existing access result. Overrides AccessEventInterface::mergeAccessResult
AccessEventBase::__construct public function Constructs an AccessEventBase event. 1
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function