Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / Context / ThemeCacheContext.php
1 <?php
2
3 namespace Drupal\Core\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Theme\ThemeManagerInterface;
7
8 /**
9  * Defines the ThemeCacheContext service, for "per theme" caching.
10  *
11  * Cache context ID: 'theme'.
12  */
13 class ThemeCacheContext implements CacheContextInterface {
14
15   /**
16    * The theme manager.
17    *
18    * @var \Drupal\Core\Theme\ThemeManagerInterface
19    */
20   protected $themeManager;
21
22   /**
23    * Constructs a new ThemeCacheContext service.
24    *
25    * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
26    *   The theme manager.
27    */
28   public function __construct(ThemeManagerInterface $theme_manager) {
29     $this->themeManager = $theme_manager;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function getLabel() {
36     return t('Theme');
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getContext() {
43     return $this->themeManager->getActiveTheme()->getName() ?: 'stark';
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getCacheableMetadata() {
50     return new CacheableMetadata();
51   }
52
53 }