.../Compiler/CacheabilitySafeguardsPass.php | 3 +-- .../src/CacheabilityBubblingNodeGrantStorage.php | 25 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php index ffe70e0..ac9a468 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/CacheabilitySafeguardsPass.php @@ -40,8 +40,7 @@ public function process(ContainerBuilder $container) { ->setPublic(FALSE); $container->register($id) ->setClass($attributes[0]['class']) - ->addArgument(new Reference($decorated)) - ->addMethodCall('setContainer', [new Reference('service_container')]); + ->setArguments([new Reference($decorated), new Reference('renderer')]); } } } diff --git a/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php b/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php index f543310..c2159a3 100644 --- a/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php +++ b/core/modules/node/src/CacheabilityBubblingNodeGrantStorage.php @@ -8,6 +8,7 @@ namespace Drupal\node; use Drupal\Core\DependencyInjection\DependencySerializationTrait; +use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -23,9 +24,6 @@ * Drupal 8, to safeguard route controllers or other code that forget to do * this, this decorator also adds it to the current render context. * - * The renderer is not injected to avoid initializing the render and theme - * system for REST routes. Instead, this service is container-aware. - * * @see \Drupal\Core\Render\MetadataBubblingUrlGenerator * * @todo Remove before Drupal 9.0.0. @@ -33,9 +31,8 @@ * @ingroup node_access * @ingroup cacheability_safeguards */ -class CacheabilityBubblingNodeGrantStorage implements NodeGrantDatabaseStorageInterface, ContainerAwareInterface { +class CacheabilityBubblingNodeGrantStorage implements NodeGrantDatabaseStorageInterface { - use ContainerAwareTrait; use DependencySerializationTrait; /** @@ -46,13 +43,23 @@ class CacheabilityBubblingNodeGrantStorage implements NodeGrantDatabaseStorageIn protected $nodeGrantStorage; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Constructs a CacheabilityBubblingNodeGrantStorage object. * * @param \Drupal\node\NodeGrantDatabaseStorageInterface $node_grant_storage * The non-bubbling node grant storage. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer. */ - public function __construct(NodeGrantDatabaseStorageInterface $node_grant_storage) { + public function __construct(NodeGrantDatabaseStorageInterface $node_grant_storage, RendererInterface $renderer) { $this->nodeGrantStorage = $node_grant_storage; + $this->renderer = $renderer; } /** @@ -75,11 +82,9 @@ public function checkAll(AccountInterface $account) { public function alterQuery($query, array $tables, $op, AccountInterface $account, $base_table) { // Bubble the 'user.node_grants:$op' cache context to the current render // context. - /** @var \Drupal\Core\Render\RendererInterface $renderer */ - $renderer = $this->container->get('renderer'); - if ($renderer->hasRenderContext()) { + if ($this->renderer->hasRenderContext()) { $build = ['#cache' => ['contexts' => ['user.node_grants:' . $op]]]; - $renderer->render($build); + $this->renderer->render($build); } return $this->nodeGrantStorage->alterQuery($query, $tables, $op, $account, $base_table);