You are here

class QueryArgsCacheContext in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php \Drupal\Core\Cache\Context\QueryArgsCacheContext

Defines the QueryArgsCacheContext service, for "per query args" caching.

Cache context ID: 'url.query_args' (to vary by all query arguments). Calculated cache context ID: 'url.query_args:%key', e.g.'url.query_args:foo' (to vary by the 'foo' query argument).

Hierarchy

Expanded class hierarchy of QueryArgsCacheContext

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

File

core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php, line 19
Contains \Drupal\Core\Cache\Context\QueryArgsCacheContext.

Namespace

Drupal\Core\Cache\Context
View source
class QueryArgsCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Query arguments');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext($query_arg = NULL) {
    if ($query_arg === NULL) {
      return $this->requestStack
        ->getCurrentRequest()
        ->getQueryString();
    }
    else {
      return $this->requestStack
        ->getCurrentRequest()->query
        ->get($query_arg);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($query_arg = NULL) {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueryArgsCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context based on the parameter value. Overrides CalculatedCacheContextInterface::getCacheableMetadata
QueryArgsCacheContext::getContext public function Returns the string representation of the cache context. Overrides CalculatedCacheContextInterface::getContext
QueryArgsCacheContext::getLabel public static function Returns the label of the cache context. Overrides CalculatedCacheContextInterface::getLabel
RequestStackCacheContextBase::$requestStack protected property The request stack.
RequestStackCacheContextBase::__construct public function Constructs a new RequestStackCacheContextBase class.