QueryArgsCacheContext.php in Drupal 8
File
core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php
View source
<?php
namespace Drupal\Core\Cache\Context;
use Drupal\Core\Cache\CacheableMetadata;
class QueryArgsCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {
public static function getLabel() {
return t('Query arguments');
}
public function getContext($query_arg = NULL) {
if ($query_arg === NULL) {
$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 '';
}
public function getCacheableMetadata($query_arg = NULL) {
return new CacheableMetadata();
}
}