public function OgMembershipStateCacheContext::getContext in Organic groups 8
Returns the string representation of the cache context.
A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.
Return value
string The string representation of the cache context.
Overrides CacheContextInterface::getContext
File
- src/
Cache/ Context/ OgMembershipStateCacheContext.php, line 74
Class
- OgMembershipStateCacheContext
- Defines a cache context service, for "membership state" caching.
Namespace
Drupal\og\Cache\ContextCode
public function getContext() {
// Do not provide a cache context if there is no group in the current
// context.
$group = $this->ogContext
->getGroup();
if (empty($group)) {
return self::NO_CONTEXT;
}
/** @var \Drupal\og\OgMembershipInterface $membership */
$membership = $this->membershipManager
->getMembership($group, $this->user
->id(), OgMembershipInterface::ALL_STATES);
return $membership ? $membership
->getState() : self::NO_CONTEXT;
}