class GroupPermissionsCacheContext in Group 8
Same name and namespace in other branches
- 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
- class \Drupal\group\Cache\Context\GroupPermissionsCacheContext implements CacheContextInterface
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'
1 service uses GroupPermissionsCacheContext
File
- src/
Cache/ Context/ GroupPermissionsCacheContext.php, line 17
Namespace
Drupal\group\Cache\ContextView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupPermissionsCacheContext:: |
protected | property | The current user. | |
GroupPermissionsCacheContext:: |
protected | property | The permissions hash generator. | |
GroupPermissionsCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
GroupPermissionsCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
GroupPermissionsCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
GroupPermissionsCacheContext:: |
public | function | Constructs a new GroupMembershipPermissionsCacheContext class. |