summaryrefslogtreecommitdiffstats
path: root/core/modules/node/src/Cache
diff options
context:
space:
mode:
authorAlex Pott2015-07-08 11:50:52 (GMT)
committerAlex Pott2015-07-08 11:50:52 (GMT)
commit46e6f72399fb1d59796a2932642b1c982d5dee77 (patch)
tree7e0b57c527970e29a2a64640bce3203965dd9fbe /core/modules/node/src/Cache
parent0f4319e4182dc28867e366d5407592d883d1d830 (diff)
Issue #2512866 by lauriii, Berdir, Wim Leers, Fabianx, effulgentsia, catch, dawehner: CacheContextsManager::optimizeTokens() optimizes ['user', 'user.permissions'] to ['user'] without adding cache tags to invalidate that when the user's roles are modified
Diffstat (limited to 'core/modules/node/src/Cache')
-rw-r--r--core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
index 912309f..d304bf7 100644
--- a/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
+++ b/core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
@@ -7,8 +7,9 @@
namespace Drupal\node\Cache;
+use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CalculatedCacheContextInterface;
-use Drupal\Core\Cache\Context\UserCacheContext;
+use Drupal\Core\Cache\Context\UserCacheContextBase;
/**
* Defines the node access view cache context service.
@@ -22,7 +23,7 @@ use Drupal\Core\Cache\Context\UserCacheContext;
* @see node_query_node_access_alter()
* @ingroup node_access
*/
-class NodeAccessGrantsCacheContext extends UserCacheContext implements CalculatedCacheContextInterface {
+class NodeAccessGrantsCacheContext extends UserCacheContextBase implements CalculatedCacheContextInterface {
/**
* {@inheritdoc}
@@ -82,4 +83,19 @@ class NodeAccessGrantsCacheContext extends UserCacheContext implements Calculate
return $operation . '.' . implode(';', $grants_context_parts);
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getCacheableMetadata($operation = NULL) {
+ $cacheable_metadata = new CacheableMetadata();
+
+ if (!\Drupal::moduleHandler()->getImplementations('node_grants')) {
+ return $cacheable_metadata;
+ }
+
+ // If the site is using node grants, this cache context can not be
+ // optimized.
+ return $cacheable_metadata->setCacheMaxAge(0);
+ }
+
}