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() { $cacheable_metadata = new CacheableMetadata(); // The permissions hash changes when: // - a user is updated to have different roles; $tags = ['user:' . $this->user->id()]; // - a role is updated to have different permissions. foreach ($this->user->getRoles() as $rid) { $tags[] = "config:user.role.$rid"; } return $cacheable_metadata->setCacheTags($tags); } }