class MasqueradeCacheContext in Masquerade 8.2
Defines the MasqueradeCacheContext service, for "masquerade" caching.
Cache context ID: 'session.is_masquerading'.
Hierarchy
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\masquerade\Cache\MasqueradeCacheContext implements CacheContextInterface
Expanded class hierarchy of MasqueradeCacheContext
1 string reference to 'MasqueradeCacheContext'
1 service uses MasqueradeCacheContext
File
- src/
Cache/ MasqueradeCacheContext.php, line 15
Namespace
Drupal\masquerade\CacheView source
class MasqueradeCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
/**
* {@inheritdoc}
*/
public static function getLabel() {
return new TranslatableMarkup('User is masquerading');
}
/**
* {@inheritdoc}
*/
public function getContext() {
if ($request = $this->requestStack
->getCurrentRequest()) {
if ($request
->hasSession() && ($session = $request
->getSession())) {
if ($session
->has('masquerading')) {
// Previous account supposed to be Authenticated.
return '1';
}
}
}
return '0';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MasqueradeCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
MasqueradeCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
MasqueradeCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
RequestStackCacheContextBase:: |
protected | property | The request stack. | |
RequestStackCacheContextBase:: |
public | function | Constructs a new RequestStackCacheContextBase class. |