Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Cache / Context / IsFrontPathCacheContext.php
1 <?php
2
3 namespace Drupal\Core\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Path\PathMatcherInterface;
7
8 /**
9  * Defines a cache context for whether the URL is the front page of the site.
10  *
11  * Cache context ID: 'url.path.is_front'.
12  */
13 class IsFrontPathCacheContext implements CacheContextInterface {
14
15   /**
16    * @var \Drupal\Core\Path\PathMatcherInterface
17    */
18   protected $pathMatcher;
19
20   /**
21    * Constructs an IsFrontPathCacheContext object.
22    *
23    * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
24    */
25   public function __construct(PathMatcherInterface $path_matcher) {
26     $this->pathMatcher = $path_matcher;
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public static function getLabel() {
33     return t('Is front page');
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function getContext() {
40     return 'is_front.' . (int) $this->pathMatcher->isFrontPage();
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getCacheableMetadata() {
47     $metadata = new CacheableMetadata();
48     $metadata->addCacheTags(['config:system.site']);
49     return $metadata;
50   }
51
52 }