diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 9aeda19..1e0e702 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -6,7 +6,7 @@ services: - { name: breadcrumb_builder, priority: 701 } book.manager: class: Drupal\book\BookManager - arguments: ['@entity.manager', '@string_translation', '@config.factory', '@book.outline_storage'] + arguments: ['@entity.manager', '@string_translation', '@config.factory', '@book.outline_storage', '@current_user'] book.outline: class: Drupal\book\BookOutline arguments: ['@book.manager'] diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index bd042b9..0573b13 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -64,13 +64,25 @@ class BookManager implements BookManagerInterface { protected $bookTreeFlattened; /** + * The curent user. + * @var \Drupal\Core\Session\AccountInterface + */ + protected $account; + + /** * Constructs a BookManager object. + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $translation + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * @param \Drupal\book\BookOutlineStorageInterface $book_outline_storage + * @param \Drupal\book\AcocuntInterface $account */ - public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage) { + public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage, AccountInterface $account) { $this->entityManager = $entity_manager; $this->stringTranslation = $translation; $this->configFactory = $config_factory; $this->bookOutlineStorage = $book_outline_storage; + $this->account = $account; } /** @@ -688,14 +700,14 @@ protected function flatBookTree(array $tree, array &$flat) { */ public function loadBookLink($nid, $translate = TRUE) { $node = $this->entityManager->getStorage('node')->load($nid); - $links = $this->loadBookLinks([$node], $translate); + $links = $this->loadBookLinks([$node->id() => $node], $translate); return isset($links[$nid]) ? $links[$nid] : FALSE; } /** * {@inheritdoc} */ - public function loadBookLinks($nodes, $translate = TRUE) { + public function loadBookLinks(array $nodes, $translate = TRUE) { $result = $this->bookOutlineStorage->loadMultiple(array_keys($nodes), $translate); $links = array(); foreach ($result as $link) { diff --git a/core/modules/book/src/BookManagerInterface.php b/core/modules/book/src/BookManagerInterface.php index cf11265..6f68683 100644 --- a/core/modules/book/src/BookManagerInterface.php +++ b/core/modules/book/src/BookManagerInterface.php @@ -79,7 +79,7 @@ public function loadBookLink($nid, $translate = TRUE); * @return array[] * The book data of each node keyed by NID. */ - public function loadBookLinks($nodes, $translate = TRUE); + public function loadBookLinks(array $nodes, $translate = TRUE); /** * Returns an array of book pages in table of contents order.