3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Path\PathMatcherInterface;
9 * Defines a cache context for whether the URL is the front page of the site.
11 * Cache context ID: 'url.path.is_front'.
13 class IsFrontPathCacheContext implements CacheContextInterface {
16 * @var \Drupal\Core\Path\PathMatcherInterface
18 protected $pathMatcher;
21 * Constructs an IsFrontPathCacheContext object.
23 * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
25 public function __construct(PathMatcherInterface $path_matcher) {
26 $this->pathMatcher = $path_matcher;
32 public static function getLabel() {
33 return t('Is front page');
39 public function getContext() {
40 return 'is_front.' . (int) $this->pathMatcher->isFrontPage();
46 public function getCacheableMetadata() {
47 $metadata = new CacheableMetadata();
48 $metadata->addCacheTags(['config:system.site']);