3 namespace Drupal\Core\Cache\Context;
5 use Drupal\Core\Cache\CacheableMetadata;
8 * Defines a cache context service for path parents.
10 * Cache context ID: 'url.path.parent'.
12 * This allows for caching based on the path, excluding everything after the
15 class PathParentCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
20 public static function getLabel() {
21 return t('Parent path');
27 public function getContext() {
28 $request = $this->requestStack->getCurrentRequest();
29 $path_elements = explode('/', trim($request->getPathInfo(), '/'));
30 array_pop($path_elements);
31 return implode('/', $path_elements);
37 public function getCacheableMetadata() {
38 return new CacheableMetadata();