annotate core/modules/workspaces/src/WorkspaceCacheContext.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 <?php
Chris@17 2
Chris@17 3 namespace Drupal\workspaces;
Chris@17 4
Chris@17 5 use Drupal\Core\Cache\CacheableMetadata;
Chris@17 6 use Drupal\Core\Cache\Context\CacheContextInterface;
Chris@17 7
Chris@17 8 /**
Chris@17 9 * Defines the WorkspaceCacheContext service, for "per workspace" caching.
Chris@17 10 *
Chris@17 11 * Cache context ID: 'workspace'.
Chris@17 12 */
Chris@17 13 class WorkspaceCacheContext implements CacheContextInterface {
Chris@17 14
Chris@17 15 /**
Chris@17 16 * The workspace manager.
Chris@17 17 *
Chris@17 18 * @var \Drupal\workspaces\WorkspaceManagerInterface
Chris@17 19 */
Chris@17 20 protected $workspaceManager;
Chris@17 21
Chris@17 22 /**
Chris@17 23 * Constructs a new WorkspaceCacheContext service.
Chris@17 24 *
Chris@17 25 * @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
Chris@17 26 * The workspace manager.
Chris@17 27 */
Chris@17 28 public function __construct(WorkspaceManagerInterface $workspace_manager) {
Chris@17 29 $this->workspaceManager = $workspace_manager;
Chris@17 30 }
Chris@17 31
Chris@17 32 /**
Chris@17 33 * {@inheritdoc}
Chris@17 34 */
Chris@17 35 public static function getLabel() {
Chris@17 36 return t('Workspace');
Chris@17 37 }
Chris@17 38
Chris@17 39 /**
Chris@17 40 * {@inheritdoc}
Chris@17 41 */
Chris@17 42 public function getContext() {
Chris@17 43 return $this->workspaceManager->getActiveWorkspace()->id();
Chris@17 44 }
Chris@17 45
Chris@17 46 /**
Chris@17 47 * {@inheritdoc}
Chris@17 48 */
Chris@17 49 public function getCacheableMetadata($type = NULL) {
Chris@17 50 // The active workspace will always be stored in the user's session.
Chris@17 51 $cacheability = new CacheableMetadata();
Chris@17 52 $cacheability->addCacheContexts(['session']);
Chris@17 53
Chris@17 54 return $cacheability;
Chris@17 55 }
Chris@17 56
Chris@17 57 }