You are here

class SocialGroupJoinMethodCacheContext in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php \Drupal\social_group\CacheContext\SocialGroupJoinMethodCacheContext
  2. 10.3.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php \Drupal\social_group\CacheContext\SocialGroupJoinMethodCacheContext
  3. 10.0.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php \Drupal\social_group\CacheContext\SocialGroupJoinMethodCacheContext
  4. 10.2.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php \Drupal\social_group\CacheContext\SocialGroupJoinMethodCacheContext

Class SocialGroupJoinMethodCacheContext.

Hierarchy

Expanded class hierarchy of SocialGroupJoinMethodCacheContext

1 string reference to 'SocialGroupJoinMethodCacheContext'
social_group.services.yml in modules/social_features/social_group/social_group.services.yml
modules/social_features/social_group/social_group.services.yml
1 service uses SocialGroupJoinMethodCacheContext
cache_context.social_group_join_method in modules/social_features/social_group/social_group.services.yml
Drupal\social_group\CacheContext\SocialGroupJoinMethodCacheContext

File

modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php, line 12

Namespace

Drupal\social_group\CacheContext
View source
class SocialGroupJoinMethodCacheContext implements CacheContextInterface {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    \Drupal::messenger()
      ->addMessage('Cache context for the join methods');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {

    // This will return the join method of the current group.
    $group = _social_group_get_current_group();
    if ($group instanceof Group && $group
      ->hasField('field_group_allowed_join_method')) {
      if (!empty($group
        ->getFieldValue('field_group_allowed_join_method', 'value'))) {
        return $group
          ->getFieldValue('field_group_allowed_join_method', 'value');
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialGroupJoinMethodCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
SocialGroupJoinMethodCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
SocialGroupJoinMethodCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel