class PathParentCacheContext
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php \Drupal\Core\Cache\Context\PathParentCacheContext
Defines a cache context service for path parents.
Cache context ID: 'url.path.parent'.
This allows for caching based on the path, excluding everything after the last forward slash.
Hierarchy
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\Core\Cache\Context\PathParentCacheContext extends \Drupal\Core\Cache\Context\CacheContextInterface implements \Drupal\Core\Cache\Context\RequestStackCacheContextBase
Expanded class hierarchy of PathParentCacheContext
1 file declares its use of PathParentCacheContext
- PathParentCacheContextTest.php in core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ PathParentCacheContextTest.php
1 string reference to 'PathParentCacheContext'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses PathParentCacheContext
File
-
core/
lib/ Drupal/ Core/ Cache/ Context/ PathParentCacheContext.php, line 15
Namespace
Drupal\Core\Cache\ContextView source
class PathParentCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Parent path');
}
/**
* {@inheritdoc}
*/
public function getContext() {
$request = $this->requestStack
->getCurrentRequest();
$path_elements = explode('/', trim($request->getPathInfo(), '/'));
array_pop($path_elements);
return implode('/', $path_elements);
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.