Skip to content
Snippets Groups Projects
Commit ba1b14e4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2430397 by Wim Leers, Fabianx: When mapping cache contexts to cache...

Issue #2430397 by Wim Leers, Fabianx: When mapping cache contexts to cache keys, include the cache context ID for easier debugging
parent 0d06b250
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -49,7 +49,7 @@ public static function getLabel() {
* {@inheritdoc}
*/
public function getContext() {
return 'ph.' . $this->permissionsHashGenerator->generate($this->user);
return $this->permissionsHashGenerator->generate($this->user);
}
/**
......
......@@ -120,9 +120,9 @@ public function convertTokensToKeys(array $context_tokens) {
sort($optimized_tokens);
$keys = [];
foreach (static::parseTokens($optimized_tokens) as $context) {
foreach (array_combine($optimized_tokens, static::parseTokens($optimized_tokens)) as $context_token => $context) {
list($context_id, $parameter) = $context;
$keys[] = $this->getService($context_id)->getContext($parameter);
$keys[] = '[' . $context_token . ']=' . $this->getService($context_id)->getContext($parameter);
}
// Create the returned object and merge in the cacheability metadata.
......
......@@ -34,10 +34,10 @@ 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 'pager' . $this->requestStack->getCurrentRequest()->query->get('page', '');
return $this->requestStack->getCurrentRequest()->query->get('page', '');
}
return 'pager.' . $pager_id . '.' . pager_find_page($pager_id);
return $pager_id . '.' . pager_find_page($pager_id);
}
/**
......
......@@ -27,7 +27,7 @@ public static function getLabel() {
* {@inheritdoc}
*/
public function getContext() {
return "u." . $this->user->id();
return $this->user->id();
}
/**
......
......@@ -40,10 +40,10 @@ public function getContext($role = NULL) {
return 'is-super-user';
}
if ($role === NULL) {
return 'r.' . implode(',', $this->user->getRoles());
return implode(',', $this->user->getRoles());
}
else {
return 'r.' . $role . '.' . (in_array($role, $this->user->getRoles()) ? '0' : '1');
return (in_array($role, $this->user->getRoles()) ? '0' : '1');
}
}
......
......@@ -68,7 +68,7 @@ public function getContext() {
// If we're looking at a book node, get the trail for that node.
$active_trail = $this->container->get('book.manager')
->getActiveTrailIds($node->book['bid'], $node->book);
return 'book.' . implode('|', $active_trail);
return implode('|', $active_trail);
}
/**
......
......@@ -76,14 +76,14 @@ protected function testPagerQueryParametersAndCacheContext() {
// First page.
$this->drupalGet('pager-test/query-parameters');
$this->assertText(t('Pager calls: 0'), 'Initial call to pager shows 0 calls.');
$this->assertText('pager.0.0');
$this->assertText('[url.query_args.pagers:0]=0.0');
$this->assertCacheContext('url.query_args');
// Go to last page, the count of pager calls need to go to 1.
$elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager__item--last'));
$this->drupalGet($this->getAbsoluteUrl($elements[0]['href']));
$this->assertText(t('Pager calls: 1'), 'First link call to pager shows 1 calls.');
$this->assertText('pager.0.60');
$this->assertText('[url.query_args.pagers:0]=0.60');
$this->assertCacheContext('url.query_args');
// Go back to first page, the count of pager calls need to go to 2.
......@@ -91,7 +91,7 @@ protected function testPagerQueryParametersAndCacheContext() {
$this->drupalGet($this->getAbsoluteUrl($elements[0]['href']));
$this->drupalGet($GLOBALS['base_root'] . parse_url($this->getUrl())['path'] . $elements[0]['href'], array('external' => TRUE));
$this->assertText(t('Pager calls: 2'), 'Second link call to pager shows 2 calls.');
$this->assertText('pager.0.0');
$this->assertText('[url.query_args.pagers:0]=0.0');
$this->assertCacheContext('url.query_args');
}
......
......@@ -96,9 +96,9 @@ public function testConvertTokensToKeys() {
]);
$expected = [
'baz.cnenzrgreN',
'baz.cnenzrgreO',
'bar',
'[baz:parameterA]=cnenzrgreN',
'[baz:parameterB]=cnenzrgreO',
'[foo]=bar',
];
$this->assertEquals($expected, $new_keys->getKeys());
}
......@@ -267,7 +267,7 @@ public function getContext($parameter = NULL) {
if (!is_string($parameter) || strlen($parameter) === 0) {
throw new \Exception();
}
return 'baz.' . str_rot13($parameter);
return str_rot13($parameter);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment