You are here

public function GroupMembership::getGroupOperationsCacheableMetadata in Group 2.0.x

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 GroupRelationBase::getGroupOperationsCacheableMetadata

See also

::getGroupOperations()

File

src/Plugin/Group/Relation/GroupMembership.php, line 61

Class

GroupMembership
Provides a group relation plugin for users as members.

Namespace

Drupal\group\Plugin\Group\Relation

Code

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;
}