class PagersCacheContext

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php \Drupal\Core\Cache\Context\PagersCacheContext
  2. 10 core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php \Drupal\Core\Cache\Context\PagersCacheContext
  3. 11.x core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php \Drupal\Core\Cache\Context\PagersCacheContext

Defines a cache context for "per page in a pager" caching.

Cache context ID: 'url.query_args.pagers' (to vary by all pagers). Calculated cache context ID: 'url.query_args.pagers:%pager_id', e.g. 'url.query_args.pagers:1' (to vary by the pager with ID 1).

Hierarchy

Expanded class hierarchy of PagersCacheContext

1 string reference to 'PagersCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PagersCacheContext
cache_context.url.query_args.pagers in core/core.services.yml
Drupal\Core\Cache\Context\PagersCacheContext

File

core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php, line 16

Namespace

Drupal\Core\Cache\Context
View source
class PagersCacheContext implements CalculatedCacheContextInterface {
    use DeprecatedServicePropertyTrait;
    
    /**
     * {@inheritdoc}
     */
    protected $deprecatedProperties = [
        'requestStack' => 'request_stack',
    ];
    
    /**
     * The pager parameters.
     *
     * @var \Drupal\Core\Pager\PagerParametersInterface
     */
    protected $pagerParams;
    
    /**
     * Constructs a new PagersCacheContext object.
     *
     * @param \Drupal\Core\Pager\PagerParametersInterface $pager_params
     *   The pager parameters.
     */
    public function __construct($pager_params) {
        if (!$pager_params instanceof PagerParametersInterface) {
            @trigger_error('Calling ' . __METHOD__ . ' with a $pager_params argument that does not implement \\Drupal\\Core\\Pager\\PagerParametersInterface is deprecated in drupal:8.8.0 and is required in drupal:9.0.0. See https://www.drupal.org/node/2779457', E_USER_DEPRECATED);
            $pager_params = \Drupal::service('pager.parameters');
        }
        $this->pagerParams = $pager_params;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t('Pager');
    }
    
    /**
     * {@inheritdoc}
     *
     * @see \Drupal\Core\Pager\PagerParametersInterface::findPage()
     */
    public function getContext($pager_id = NULL) {
        // The value of the 'page' query argument contains the information that
        // controls *all* pagers.
        if ($pager_id === NULL) {
            return $this->pagerParams
                ->getPagerParameter();
        }
        return $pager_id . '.' . $this->pagerParams
            ->findPage($pager_id);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata($pager_id = NULL) {
        return new CacheableMetadata();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
PagersCacheContext::$deprecatedProperties protected property
PagersCacheContext::$pagerParams protected property The pager parameters.
PagersCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context based on the parameter value. Overrides CalculatedCacheContextInterface::getCacheableMetadata
PagersCacheContext::getContext public function Overrides CalculatedCacheContextInterface::getContext
PagersCacheContext::getLabel public static function Returns the label of the cache context. Overrides CalculatedCacheContextInterface::getLabel
PagersCacheContext::__construct public function Constructs a new PagersCacheContext object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.