public function GroupMembership::getGroupOperationsCacheableMetadata in Group 8
Provides the cacheable metadata for this plugin's group operations.
The operations set in ::getGroupOperations() may have some cacheable metadata that needs to be set but can't be because the links set in an Operations render element are simple associative arrays. This method allows you to specify the cacheable metadata regardless.
Return value
\Drupal\Core\Cache\CacheableMetadata The cacheable metadata for the group operations.
Overrides GroupContentEnablerBase::getGroupOperationsCacheableMetadata
See also
::getGroupOperations()
File
- src/
Plugin/ GroupContentEnabler/ GroupMembership.php, line 69
Class
- GroupMembership
- Provides a content enabler for users.
Namespace
Drupal\group\Plugin\GroupContentEnablerCode
public function getGroupOperationsCacheableMetadata() {
// We cannot use the user.is_group_member:%group_id cache context for the
// join and leave operations, because they end up in the group operations
// block, which is shown for most likely every group in the system. Instead,
// we cache per user, meaning the block will be auto-placeholdered in most
// set-ups.
// @todo With the new VariationCache, we can use the above context.
$cacheable_metadata = new CacheableMetadata();
$cacheable_metadata
->setCacheContexts([
'user',
]);
return $cacheable_metadata;
}