Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PathParentCacheContext.php

class 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

File

core/lib/Drupal/Core/Cache/Context/PathParentCacheContext.php, line 15

Namespace

Drupal\Core\Cache\Context
View 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 Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
PathParentCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
PathParentCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
RequestStackCacheContextBase::$requestStack protected property The request stack.
RequestStackCacheContextBase::__construct public function Constructs a new RequestStackCacheContextBase class.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal