Mercurial > hg > isophonics-drupal-site
comparison core/modules/workspaces/src/WorkspaceCacheContext.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\workspaces; | |
4 | |
5 use Drupal\Core\Cache\CacheableMetadata; | |
6 use Drupal\Core\Cache\Context\CacheContextInterface; | |
7 | |
8 /** | |
9 * Defines the WorkspaceCacheContext service, for "per workspace" caching. | |
10 * | |
11 * Cache context ID: 'workspace'. | |
12 */ | |
13 class WorkspaceCacheContext implements CacheContextInterface { | |
14 | |
15 /** | |
16 * The workspace manager. | |
17 * | |
18 * @var \Drupal\workspaces\WorkspaceManagerInterface | |
19 */ | |
20 protected $workspaceManager; | |
21 | |
22 /** | |
23 * Constructs a new WorkspaceCacheContext service. | |
24 * | |
25 * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager | |
26 * The workspace manager. | |
27 */ | |
28 public function __construct(WorkspaceManagerInterface $workspace_manager) { | |
29 $this->workspaceManager = $workspace_manager; | |
30 } | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 public static function getLabel() { | |
36 return t('Workspace'); | |
37 } | |
38 | |
39 /** | |
40 * {@inheritdoc} | |
41 */ | |
42 public function getContext() { | |
43 return $this->workspaceManager->getActiveWorkspace()->id(); | |
44 } | |
45 | |
46 /** | |
47 * {@inheritdoc} | |
48 */ | |
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']); | |
53 | |
54 return $cacheability; | |
55 } | |
56 | |
57 } |