core/modules/book/book.services.yml | 2 +- .../book/src/Cache/BookNavigationCacheContext.php | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 8f7384d..440d021 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -25,6 +25,6 @@ services: - { name: access_check, applies_to: _access_book_removable } cache_context.book.navigation: class: Drupal\book\Cache\BookNavigationCacheContext - arguments: ['@book.manager', '@request_stack'] + arguments: ['@request_stack'] tags: - { name: cache.context} diff --git a/core/modules/book/src/Cache/BookNavigationCacheContext.php b/core/modules/book/src/Cache/BookNavigationCacheContext.php index 516bd07..531611f 100644 --- a/core/modules/book/src/Cache/BookNavigationCacheContext.php +++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php @@ -7,8 +7,8 @@ namespace Drupal\book\Cache; -use Drupal\book\BookManagerInterface; use Drupal\Core\Cache\CacheContextInterface; +use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -17,15 +17,11 @@ * This allows for book navigation location-aware caching. It depends on: * - whether the current route represents a book node at all * - and if so, where in the book hierarchy we are + * + * This class is container-aware to avoid initializing the 'book.manager' + * service when it is not necessary. */ -class BookNavigationCacheContext implements CacheContextInterface { - - /** - * The book manager. - * - * @var \Drupal\book\BookManagerInterface - */ - protected $bookManager; +class BookNavigationCacheContext extends ContainerAware implements CacheContextInterface { /** * The request stack. @@ -37,13 +33,10 @@ class BookNavigationCacheContext implements CacheContextInterface { /** * Constructs a new BookNavigationCacheContext service. * - * @param \Drupal\book\BookManagerInterface $book_manager - * The book manager. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack. */ - public function __construct(BookManagerInterface $book_manager, RequestStack $request_stack) { - $this->bookManager = $book_manager; + public function __construct(RequestStack $request_stack) { $this->requestStack = $request_stack; } @@ -70,7 +63,8 @@ public function getContext() { } // If we're looking at a book node, get the trail for that node. - $active_trail = $this->bookManager->getActiveTrailIds($node->book['bid'], $node->book); + $active_trail = $this->container->get('book.manager') + ->getActiveTrailIds($node->book['bid'], $node->book); return 'book.' . implode('|', $active_trail); }