You are here

class GroupPermissionsCacheContext in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Cache/Context/GroupPermissionsCacheContext.php \Drupal\group\Cache\Context\GroupPermissionsCacheContext

Defines a cache context for "per group membership permissions" caching.

Please read the following guide on how to best use this context: https://www.drupal.org/docs/8/modules/group/turning-off-caching-when-it-....

Cache context ID: 'user.group_permissions'.

Hierarchy

Expanded class hierarchy of GroupPermissionsCacheContext

1 file declares its use of GroupPermissionsCacheContext
GroupPermissionsCacheContextTest.php in tests/src/Unit/GroupPermissionsCacheContextTest.php
1 string reference to 'GroupPermissionsCacheContext'
group.services.yml in ./group.services.yml
group.services.yml
1 service uses GroupPermissionsCacheContext
cache_context.user.group_permissions in ./group.services.yml
Drupal\group\Cache\Context\GroupPermissionsCacheContext

File

src/Cache/Context/GroupPermissionsCacheContext.php, line 17

Namespace

Drupal\group\Cache\Context
View source
class GroupPermissionsCacheContext implements CacheContextInterface {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * The permissions hash generator.
   *
   * @var \Drupal\group\Access\GroupPermissionsHashGeneratorInterface
   */
  protected $permissionsHashGenerator;

  /**
   * Constructs a new GroupMembershipPermissionsCacheContext class.
   *
   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
   *   The current user.
   * @param \Drupal\group\Access\GroupPermissionsHashGeneratorInterface $hash_generator
   *   The permissions hash generator.
   */
  public function __construct(AccountProxyInterface $current_user, GroupPermissionsHashGeneratorInterface $hash_generator) {
    $this->currentUser = $current_user;
    $this->permissionsHashGenerator = $hash_generator;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t("Group permissions");
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {

    // @todo Take bypass permission into account, delete permission in 8.2.x.
    return $this->permissionsHashGenerator
      ->generateHash($this->currentUser);
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {

    // @todo Take bypass permission into account, delete permission in 8.2.x.
    return $this->permissionsHashGenerator
      ->getCacheableMetadata($this->currentUser);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GroupPermissionsCacheContext::$currentUser protected property The current user.
GroupPermissionsCacheContext::$permissionsHashGenerator protected property The permissions hash generator.
GroupPermissionsCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
GroupPermissionsCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
GroupPermissionsCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
GroupPermissionsCacheContext::__construct public function Constructs a new GroupMembershipPermissionsCacheContext class.