SocialGroupJoinMethodCacheContext.php in Open Social 10.1.x
Same filename and directory in other branches
- 8.9 modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php
- 10.3.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php
- 10.0.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php
- 10.2.x modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.php
Namespace
Drupal\social_group\CacheContextFile
modules/social_features/social_group/src/CacheContext/SocialGroupJoinMethodCacheContext.phpView source
<?php
namespace Drupal\social_group\CacheContext;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
use Drupal\group\Entity\Group;
/**
* Class SocialGroupJoinMethodCacheContext.
*/
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();
}
}
Classes
Name | Description |
---|---|
SocialGroupJoinMethodCacheContext | Class SocialGroupJoinMethodCacheContext. |