class PathParentCacheContext
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php \Drupal\Core\Cache\Context\PathParentCacheContext
- 8.9.x core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php \Drupal\Core\Cache\Context\PathParentCacheContext
- 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\RequestStackCacheContextBase implements \Drupal\Core\Cache\Context\CacheContextInterface
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();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
PathParentCacheContext::getCacheableMetadata | public | function | Overrides CacheContextInterface::getCacheableMetadata | |
PathParentCacheContext::getContext | public | function | Overrides CacheContextInterface::getContext | |
PathParentCacheContext::getLabel | public static | function | Overrides CacheContextInterface::getLabel | |
RequestStackCacheContextBase::$requestStack | protected | property | The request stack. | |
RequestStackCacheContextBase::__construct | public | function | Constructs a new RequestStackCacheContextBase class. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.