function UserRolesCacheContext::getCacheableMetadata

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getCacheableMetadata()
  2. 10 core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getCacheableMetadata()
  3. 11.x core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getCacheableMetadata()

Overrides CalculatedCacheContextInterface::getCacheableMetadata

File

core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php, line 48

Class

UserRolesCacheContext
Defines the UserRolesCacheContext service, for "per role" caching.

Namespace

Drupal\Core\Cache\Context

Code

public function getCacheableMetadata($role = NULL) {
    return (new CacheableMetadata())->setCacheTags([
        'user:' . $this->user
            ->id(),
    ]);
}

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