class QueryArgsCacheContext in Drupal 9
Same name and namespace in other branches
- 8 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
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\Core\Cache\Context\QueryArgsCacheContext implements CalculatedCacheContextInterface
Expanded class hierarchy of QueryArgsCacheContext
1 file declares its use of QueryArgsCacheContext
- QueryArgsCacheContextTest.php in core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ QueryArgsCacheContextTest.php
1 string reference to 'QueryArgsCacheContext'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses QueryArgsCacheContext
File
- core/
lib/ Drupal/ Core/ Cache/ Context/ QueryArgsCacheContext.php, line 14
Namespace
Drupal\Core\Cache\ContextView 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) {
// All arguments requested. Use normalized query string to minimize
// variations.
$value = $this->requestStack
->getCurrentRequest()
->getQueryString();
return $value !== NULL ? $value : '';
}
elseif ($this->requestStack
->getCurrentRequest()->query
->has($query_arg)) {
$value = $this->requestStack
->getCurrentRequest()->query
->get($query_arg);
if (is_array($value)) {
return http_build_query($value);
}
elseif ($value !== '') {
return $value;
}
return '?valueless?';
}
return '';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($query_arg = NULL) {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryArgsCacheContext:: |
public | function |
Gets the cacheability metadata for the context based on the parameter value. Overrides CalculatedCacheContextInterface:: |
|
QueryArgsCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CalculatedCacheContextInterface:: |
|
QueryArgsCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CalculatedCacheContextInterface:: |
|
RequestStackCacheContextBase:: |
protected | property | The request stack. | |
RequestStackCacheContextBase:: |
public | function | Constructs a new RequestStackCacheContextBase class. |