3 namespace Drupal\workspaces;
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Cache\Context\CacheContextInterface;
9 * Defines the WorkspaceCacheContext service, for "per workspace" caching.
11 * Cache context ID: 'workspace'.
13 class WorkspaceCacheContext implements CacheContextInterface {
16 * The workspace manager.
18 * @var \Drupal\workspaces\WorkspaceManagerInterface
20 protected $workspaceManager;
23 * Constructs a new WorkspaceCacheContext service.
25 * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
26 * The workspace manager.
28 public function __construct(WorkspaceManagerInterface $workspace_manager) {
29 $this->workspaceManager = $workspace_manager;
35 public static function getLabel() {
36 return t('Workspace');
42 public function getContext() {
43 return $this->workspaceManager->getActiveWorkspace()->id();
49 public function getCacheableMetadata($type = NULL) {
50 // The active workspace will always be stored in the user's session.
51 $cacheability = new CacheableMetadata();
52 $cacheability->addCacheContexts(['session']);