class AccountPermissionsCacheContext

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php \Drupal\Core\Cache\Context\AccountPermissionsCacheContext
  2. 8.9.x core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php \Drupal\Core\Cache\Context\AccountPermissionsCacheContext
  3. 10 core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php \Drupal\Core\Cache\Context\AccountPermissionsCacheContext

Defines the AccountPermissionsCacheContext service, for "per permission" caching.

Cache context ID: 'user.permissions'.

Hierarchy

Expanded class hierarchy of AccountPermissionsCacheContext

File

core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php, line 13

Namespace

Drupal\Core\Cache\Context
View source
class AccountPermissionsCacheContext extends UserCacheContextBase implements CacheContextInterface {
    
    /**
     * The permissions hash generator.
     *
     * @var \Drupal\Core\Session\PermissionsHashGeneratorInterface
     */
    protected $permissionsHashGenerator;
    
    /**
     * Constructs a new UserCacheContext service.
     *
     * @param \Drupal\Core\Session\AccountInterface $user
     *   The current user.
     * @param \Drupal\Core\Session\PermissionsHashGeneratorInterface $permissions_hash_generator
     *   The permissions hash generator.
     */
    public function __construct(AccountInterface $user, PermissionsHashGeneratorInterface $permissions_hash_generator) {
        $this->user = $user;
        $this->permissionsHashGenerator = $permissions_hash_generator;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t("Account's permissions");
    }
    
    /**
     * {@inheritdoc}
     */
    public function getContext() {
        return $this->permissionsHashGenerator
            ->generate($this->user);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata() {
        return $this->permissionsHashGenerator
            ->getCacheableMetadata($this->user);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AccountPermissionsCacheContext::$permissionsHashGenerator protected property The permissions hash generator.
AccountPermissionsCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
AccountPermissionsCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
AccountPermissionsCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
AccountPermissionsCacheContext::__construct public function Constructs a new UserCacheContext service. Overrides UserCacheContextBase::__construct
UserCacheContextBase::$user protected property The account object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.