class WorkspaceCacheContext in Drupal 9
Same name and namespace in other branches
- 8 core/modules/workspaces/src/WorkspaceCacheContext.php \Drupal\workspaces\WorkspaceCacheContext
- 10 core/modules/workspaces/src/WorkspaceCacheContext.php \Drupal\workspaces\WorkspaceCacheContext
Defines the WorkspaceCacheContext service, for "per workspace" caching.
Cache context ID: 'workspace'.
Hierarchy
- class \Drupal\workspaces\WorkspaceCacheContext implements CacheContextInterface
Expanded class hierarchy of WorkspaceCacheContext
1 file declares its use of WorkspaceCacheContext
- WorkspaceCacheContextTest.php in core/
modules/ workspaces/ tests/ src/ Functional/ WorkspaceCacheContextTest.php
1 string reference to 'WorkspaceCacheContext'
- workspaces.services.yml in core/
modules/ workspaces/ workspaces.services.yml - core/modules/workspaces/workspaces.services.yml
1 service uses WorkspaceCacheContext
- cache_context.workspace in core/
modules/ workspaces/ workspaces.services.yml - Drupal\workspaces\WorkspaceCacheContext
File
- core/
modules/ workspaces/ src/ WorkspaceCacheContext.php, line 13
Namespace
Drupal\workspacesView source
class WorkspaceCacheContext implements CacheContextInterface {
/**
* The workspace manager.
*
* @var \Drupal\workspaces\WorkspaceManagerInterface
*/
protected $workspaceManager;
/**
* Constructs a new WorkspaceCacheContext service.
*
* @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
* The workspace manager.
*/
public function __construct(WorkspaceManagerInterface $workspace_manager) {
$this->workspaceManager = $workspace_manager;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Workspace');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return $this->workspaceManager
->hasActiveWorkspace() ? $this->workspaceManager
->getActiveWorkspace()
->id() : 'live';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($type = NULL) {
// The active workspace will always be stored in the user's session.
$cacheability = new CacheableMetadata();
$cacheability
->addCacheContexts([
'session',
]);
return $cacheability;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WorkspaceCacheContext:: |
protected | property | The workspace manager. | |
WorkspaceCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
WorkspaceCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
WorkspaceCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
WorkspaceCacheContext:: |
public | function | Constructs a new WorkspaceCacheContext service. |