core/core.services.yml | 1 - core/lib/Drupal/Core/CoreServiceProvider.php | 3 - .../Compiler/CacheabilitySafeguardsPass.php | 59 ---------- core/modules/node/node.module | 8 ++ core/modules/node/node.services.yml | 1 - .../src/CacheabilityBubblingNodeGrantStorage.php | 128 --------------------- .../Compiler/CacheabilitySafeguardsPassTest.php | 85 -------------- sites/default/default.services.yml | 2 - 8 files changed, 8 insertions(+), 279 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 3428dc2..a83af34 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -14,7 +14,6 @@ parameters: max-age: 0 contexts: ['session', 'user'] tags: [] - renderer.cacheability_safeguards: true factory.keyvalue: default: keyvalue.database http.response.debug_cacheability_headers: false diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php index 21fe06c..101c3bc 100644 --- a/core/lib/Drupal/Core/CoreServiceProvider.php +++ b/core/lib/Drupal/Core/CoreServiceProvider.php @@ -10,7 +10,6 @@ use Drupal\Core\Cache\Context\CacheContextsPass; use Drupal\Core\Cache\ListCacheBinsPass; use Drupal\Core\DependencyInjection\Compiler\BackendCompilerPass; -use Drupal\Core\DependencyInjection\Compiler\CacheabilitySafeguardsPass; use Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass; use Drupal\Core\DependencyInjection\Compiler\ContextProvidersPass; use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass; @@ -101,8 +100,6 @@ public function register(ContainerBuilder $container) { $container->addCompilerPass(new PluginManagerPass()); $container->addCompilerPass(new DependencySerializationTraitPass()); - - $container->addCompilerPass(new CacheabilitySafeguardsPass()); } /** diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php deleted file mode 100644 index 63ca6d6..0000000 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php +++ /dev/null @@ -1,59 +0,0 @@ -hasParameter('renderer.cacheability_safeguards') && $container->getParameter('renderer.cacheability_safeguards') === FALSE; - - foreach ($container->findTaggedServiceIds('cacheability_safeguard') as $id => $attributes) { - $non_bubbling = $id . '.non_bubbling'; - - // Regardless of whether the guard is up or down, make sure the - // non-bubbling service is available for injection, but does not have to - // be public. - if ($guard_down) { - $container->setAlias($non_bubbling, new Alias($id, FALSE)); - } - else { - // Decorate the non-bubbling service with a bubbling implementation; use - // a random ID so that the bubbling service is only ever accessed via - // its original name. - $random = new Random(); - $container->register($id . '.' . strtolower($random->name()), $attributes[0]['class']) - ->setArguments([new Reference($non_bubbling), new Reference('renderer')]) - ->setPublic(false) - ->setDecoratedService($id, $non_bubbling); - } - } - } - -} diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 896c4f8..a54fc0a 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1064,6 +1064,14 @@ function node_query_node_access_alter(AlterableInterface $query) { // Update the query for the given storage method. \Drupal::service('node.grant_storage')->alterQuery($query, $tables, $op, $account, $base_table); + + // Bubble the 'user.node_grants:$op' cache context to the current render + // context. + $renderer = \Drupal::service('renderer'); + if ($renderer->hasRenderContext()) { + $build = ['#cache' => ['contexts' => ['user.node_grants:' . $op]]]; + $renderer->render($build); + } } /** diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml index 829f46c..2ff32c3 100644 --- a/core/modules/node/node.services.yml +++ b/core/modules/node/node.services.yml @@ -8,7 +8,6 @@ services: arguments: ['@database', '@module_handler', '@language_manager'] tags: - { name: backend_overridable } - - { name: cacheability_safeguard, class: 'Drupal\node\CacheabilityBubblingNodeGrantStorage' } access_check.node.revision: class: Drupal\node\Access\NodeRevisionAccessCheck arguments: ['@entity.manager'] diff --git a/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php b/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php deleted file mode 100644 index d29d0d7..0000000 --- a/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php +++ /dev/null @@ -1,128 +0,0 @@ -nodeGrantStorage = $node_grant_storage; - $this->renderer = $renderer; - } - - /** - * {@inheritdoc} - */ - public function access(NodeInterface $node, $operation, AccountInterface $account) { - return $this->nodeGrantStorage->access($node, $operation, $account); - } - - /** - * {@inheritdoc} - */ - public function checkAll(AccountInterface $account) { - return $this->nodeGrantStorage->checkAll($account); - } - - /** - * {@inheritdoc} - */ - public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table) { - // Bubble the 'user.node_grants:$op' cache context to the current render - // context. - if ($this->renderer->hasRenderContext()) { - $build = ['#cache' => ['contexts' => ['user.node_grants:' . $op]]]; - $this->renderer->render($build); - } - - return $this->nodeGrantStorage->alterQuery($query, $tables, $op, $account, $base_table); - } - - /** - * {@inheritdoc} - */ - public function write(NodeInterface $node, array $grants, $realm = NULL, $delete = TRUE) { - return $this->nodeGrantStorage->write($node, $grants, $realm, $delete); - } - - /** - * {@inheritdoc} - */ - public function delete() { - return $this->nodeGrantStorage->delete(); - } - - /** - * {@inheritdoc} - */ - public function writeDefault() { - return $this->nodeGrantStorage->writeDefault(); - } - - /** - * {@inheritdoc} - */ - public function count() { - return $this->nodeGrantStorage->count(); - } - - /** - * {@inheritdoc} - */ - public function deleteNodeRecords(array $nids) { - return $this->nodeGrantStorage->deleteNodeRecords($nids); - } - -} diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPassTest.php deleted file mode 100644 index 9cd68e6..0000000 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPassTest.php +++ /dev/null @@ -1,85 +0,0 @@ -setParameter('renderer.cacheability_safeguards', $safeguards_enabled); - } - $container->register('renderer', __NAMESPACE__ . '\Renderer'); - $definition = new Definition(__NAMESPACE__ . '\Llama'); - $definition->addTag( - 'cacheability_safeguard', - ['class' => __NAMESPACE__ . '\BubblingLlama'] - ); - $container->setDefinition('llama', $definition); - $container->setDefinition('llama_consumer', (new Definition(__NAMESPACE__ . '\LlamaConsumer'))->addArgument(new Reference('llama'))); - $container->setDefinition('advanced_llama_consumer', (new Definition(__NAMESPACE__ . '\LlamaConsumer'))->addArgument(new Reference('llama.non_bubbling'))); - - // Apply the CacheabilitySafeguardsPass compiler pass. - $handler_pass = new CacheabilitySafeguardsPass(); - $handler_pass->process($container); - // The CacheabilitySafeguardsPass creates decorated services, so we must - // apply the DecoratorServicePass also. - $decorator_pass = new DecoratorServicePass(); - $decorator_pass->process($container); - - $this->assertInstanceOf(__NAMESPACE__ . '\\' . $expected_llama_class, $container->get('llama')); - $this->assertInstanceOf(__NAMESPACE__ . '\\' . $expected_llama_class, $container->get('llama_consumer')->llama); - $this->assertInstanceOf(__NAMESPACE__ . '\\' . $expected_non_bubbling_llama_class, $container->get('advanced_llama_consumer')->llama); - } - - /** - * Provides test data for testCacheabilitySafeguards(). - * - * @return array - */ - public function cacheabilitySafeguardsProvider() { - return [ - 'default' => [NULL, 'BubblingLlama', 'Llama'], - 'enabled' => [TRUE, 'BubblingLlama', 'Llama'], - 'disabled' => [FALSE, 'Llama', 'Llama'], - ]; - } - -} - -class Llama {} -class BubblingLlama { - // This ensures that the expected arguments are received. - function __construct(Llama $llama, Renderer $renderer) {} -} - -class LlamaConsumer { - // Publicly expose the consumed llama so we can test it. - public $llama; - function __construct($llama) { - $this->llama = $llama; - } -} - -class Renderer {} diff --git a/sites/default/default.services.yml b/sites/default/default.services.yml index 8be9f18..23f6483 100644 --- a/sites/default/default.services.yml +++ b/sites/default/default.services.yml @@ -115,8 +115,6 @@ parameters: # # @default [] tags: [] - # Whether renderer cacheability safeguards should be enabled or not. - renderer.cacheability_safeguards: true # Cacheability debugging: # # Responses with cacheability metadata (CacheableResponseInterface instances)