IsFrontPathCacheContext.php in Drupal 8
File
core/lib/Drupal/Core/Cache/Context/IsFrontPathCacheContext.php
View source
<?php
namespace Drupal\Core\Cache\Context;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Path\PathMatcherInterface;
class IsFrontPathCacheContext implements CacheContextInterface {
protected $pathMatcher;
public function __construct(PathMatcherInterface $path_matcher) {
$this->pathMatcher = $path_matcher;
}
public static function getLabel() {
return t('Is front page');
}
public function getContext() {
return 'is_front.' . (int) $this->pathMatcher
->isFrontPage();
}
public function getCacheableMetadata() {
$metadata = new CacheableMetadata();
$metadata
->addCacheTags([
'config:system.site',
]);
return $metadata;
}
}