class PathParentCacheContext in Drupal 9
Same name and namespace in other branches
- 8 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 implements 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathParentCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
PathParentCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
PathParentCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
RequestStackCacheContextBase:: |
protected | property | The request stack. | |
RequestStackCacheContextBase:: |
public | function | Constructs a new RequestStackCacheContextBase class. |