BookManager service public function bookTreeAllData gives error in non-node context (search indexing)

Created on 22 March 2021, over 4 years ago
Updated 21 July 2023, almost 2 years ago

Problem/Motivation

I'm trying to use the public function on this service to render some custom content blocks showing a (partial) book outline. The documentation states:

* Gets the data structure representing a named menu tree.
*
* Since this can be the full tree including hidden items, the data returned
* may be used for generating an admin interface or a select.

This is a public function on a service although it looks like in core it is only used in the book block.

In my case when the content rendered with the custom book data is indexed using search_api the bookTreeAllData function will eventually call the buildBookOutlineRecursive function and then an error is thrown in this section of the code:

  protected function buildBookOutlineRecursive(&$links, $parents, $depth) {
    $tree = [];
    $node = \Drupal::routeMatch()->getParameter('node');
    if (!($node instanceof NodeInterface)) {
      $node = $this->entityTypeManager->getStorage('node')->load($node);
    }

Steps to reproduce

Use bookTreeAllData in a custom theme or module to render extra content about another book on a node. Index the node in search_api.

Proposed resolution

I would guess that we shouldn't assume that there is a current node available in routeMatch when loading the book outline?

Please excuse me if I should be using another function instead to get a book menu. However, if so I think this function documentation may need changing.

πŸ› Bug report
Status

Postponed

Version

9.5

Component
BookΒ  β†’

Last updated 1 day ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @pwolanin
Created by

πŸ‡¨πŸ‡¦Canada lolcode

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024