Problem/Motivation

After installing Drupal core 11.3.8

Error: Call to undefined method Drupal\node\Entity\Node::getBook() in Drupal\book\Plugin\Condition\Book->evaluate() (line 120 of /web/liebdev/web/modules/contrib/book/src/Plugin/Condition/Book.php).

The site is broken. Cannot load any page.
I sidestepped the problem by comment lines 120-124 in /book/src/Plugin/Condition/Book.php

Steps to reproduce

This happened after the update to core 11.3.8. It was working fine in 11.3.7
I have another site with Book 2.0.4 and the 11.3.8 update did not break that one.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork book-3585906

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lieb created an issue. See original summary.

jon.lund’s picture

I am getting this error on all pages site wide. This occurred on update to ^3.0.2

Error: Call to undefined method Drupal\node\Entity\Node::getBook() in Drupal\book\Plugin\Block\BookNavigationBlock->build() (line 176 of modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php).
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func_array('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 107)
Drupal\Core\Render\Renderer->doTrustedCallback('Drupal\block\BlockViewBuilder::preRender', Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 910)
Drupal\Core\Render\Renderer->doCallback('#pre_render', 'Drupal\block\BlockViewBuilder::preRender', Array) (Line: 441)

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
smustgrave’s picture

Please confirm if the latest release fixed the issue. 3.0.2 had a big change that was needed

jon.lund’s picture

The update from 3.0.0 to 3.0.2 is what introduced the issue on my system.

Seems to be a very similar issue. These are content types that have no Book configuration at all. They are not parents or children content types. There is a Book Navigation Block displayed on the page layout that displays all available Book(s) Top Level. Here is the stack trace.
The website encountered an unexpected error. Try again later.

Error: Call to undefined method Drupal\node\Entity\Node::getBook() in Drupal\book\Plugin\Block\BookNavigationBlock->build() (line 218 of modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php).
Drupal\block\BlockViewBuilder::preRender()
call_user_func_array() (Line: 107)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 910)
Drupal\Core\Render\Renderer->doCallback() (Line: 441)
Drupal\Core\Render\Renderer->doRender() (Line: 513)
Drupal\Core\Render\Renderer->doRender() (Line: 230)
Drupal\Core\Render\Renderer->render() (Line: 501)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 156)
__TwigTemplate_8cafad02110efd86e6482643a4becb19->doDisplay() (Line: 402)
Twig\Template->yield() (Line: 386)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 35)
Drupal\Core\Template\TwigThemeEngine->renderTemplate() (Line: 428)
Drupal\Core\Theme\ThemeManager->render() (Line: 500)
Drupal\Core\Render\Renderer->doRender() (Line: 230)
Drupal\Core\Render\Renderer->render() (Line: 501)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 91)
__TwigTemplate_36d4d3a5e630acbe6ae8c6807f932437->doDisplay() (Line: 402)
Twig\Template->yield() (Line: 386)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 35)
Drupal\Core\Template\TwigThemeEngine->renderTemplate() (Line: 428)
Drupal\Core\Theme\ThemeManager->render() (Line: 500)
Drupal\Core\Render\Renderer->doRender() (Line: 230)
Drupal\Core\Render\Renderer->render() (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->{closure:Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse():157}() (Line: 634)
Drupal\Core\Render\Renderer::{closure:Drupal\Core\Render\Renderer::executeInRenderContext():634}()
Fiber->resume() (Line: 649)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 157)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::{closure:Symfony\Component\EventDispatcher\EventDispatcher::optimizeListeners():241}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 118)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 92)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 745)
Drupal\Core\DrupalKernel->handle() (Line: 19)

smustgrave’s picture

Thanks but did you try the MR mentioned? Did you upgrade to 3.0.3?

jon.lund’s picture

I have updated to 3.0.3 and this issue is persistent. If I remove the Book Navigation Block from the layout all pages render flawlessly. When the Book Navigation Block is present, pages that are not of a Book content type will not render.

Not sure this is proper but wrapping in a Try/Catch allows render. At line 222

$node = $this->routeMatch->getParameter('node');
if ($node instanceof NodeInterface) {
try {
$book = $node->getBook();
if (!empty($book['bid'])) {
$current_bid = $book['bid'];
}
} catch (\Throwable $th) {
//throw $th;
}
}

smustgrave’s picture

Need clearer steps as I'm not able to replicate any error.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Needs review

Try this

liam morland’s picture

lieb’s picture

Just confirming I'm still getting:

Error: Call to undefined method Drupal\node\Entity\Node::getBook() in Drupal\book\Plugin\Condition\Book->evaluate() (line 120 of ../web/modules/contrib/book/src/Plugin/Condition/Book.php).
With book 3.0.3 and core 11.3.8

My crude workaround is to comment lines 120-124 in src/Plugin/Condition/Book.php
Thanks.

liam morland’s picture

Version: 3.0.2 » 3.0.x-dev
jon.lund’s picture

I think the issue here is that book is not allowing the block navigation to display on non-book node pages and some of us want the book block navigation to display on all pages in a layout regardless of whether the current node is part of a book. My site uses book heavily including several different books as documentation and want to provide a navigation tree to those books using the existing book navigation without having to create a new menu.

smustgrave’s picture

Rebased