public function RouteGroupCacheContext::getContext in Group 8
Same name and namespace in other branches
- 2.0.x src/Cache/Context/RouteGroupCacheContext.php \Drupal\group\Cache\Context\RouteGroupCacheContext::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.
Return value
string The string representation of the cache context.
Overrides CacheContextInterface::getContext
File
- src/
Cache/ Context/ RouteGroupCacheContext.php, line 48
Class
- RouteGroupCacheContext
- Defines a cache context for "per group from route" caching.
Namespace
Drupal\group\Cache\ContextCode
public function getContext() {
if ($group = $this
->getGroupFromRoute()) {
// If a group was found on the route, we return its ID as the context.
if ($gid = $group
->id()) {
return $gid;
}
// If there was no ID, but we still have a group, we are on the group add
// form and we return the group type instead. This allows the context to
// distinguish between unsaved groups, based on their type.
return $group
->bundle();
}
// If no group was found on the route, we return a string that cannot be
// mistaken for a group ID or group type.
return 'group.none';
}