public function IsGroupMemberCacheContext::getContext in Group 8
Same name and namespace in other branches
- 2.0.x src/Cache/Context/IsGroupMemberCacheContext.php \Drupal\group\Cache\Context\IsGroupMemberCacheContext::getContext()
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.
Parameters
string|null $parameter: The parameter, or NULL to indicate all possible parameter values.
Return value
string The string representation of the cache context. When $parameter is NULL, a value representing all possible parameters must be generated.
Throws
\LogicException Thrown if the passed in parameter is invalid.
Overrides CalculatedCacheContextInterface::getContext
File
- src/
Cache/ Context/ IsGroupMemberCacheContext.php, line 81
Class
- IsGroupMemberCacheContext
- Defines a cache context for "is a group member or not" caching.
Namespace
Drupal\group\Cache\ContextCode
public function getContext($group_id = NULL) {
if (!$group_id) {
throw new \LogicException('No group ID provided for user.is_group_member cache context.');
}
$group = $this->entityTypeManager
->getStorage('group')
->load($group_id);
if (!$group) {
throw new \LogicException('Incorrect group ID provided for user.is_group_member cache context.');
}
return $this->membershipLoader
->load($group, $this->currentUser) ? '1' : '0';
}