Layout builder fatal error

Created on 22 April 2025, 3 months ago

It seems that the new toc_api 2.x version has an issue with Layout Builder, as the getCurrentToc() method returns a null value.

TypeError: Drupal\toc_api\Plugin\Block\TocBlockBase::getCurrentToc(): Return value must be of type Drupal\toc_api\TocInterface, null returned in Drupal\toc_api\Plugin\Block\TocBlockBase->getCurrentToc()

I also noticed that the getCurrentNode() function checks the route name, but it doesn't account for Layout Builder paths.

I've marked this as a major priority because it breaks the Layout Builder experience.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy finex

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

Comments & Activities

  • Issue created by @finex
  • 🇨🇦Canada joseph.olstad

    I will review merge requests and or related patches.

  • 🇨🇦Canada joseph.olstad

    Please apply the upstream patch!

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    What is the patch that needs to be applied?

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    Unless I am misunderstanding something, this should be closed as duplicate of 🐛 Fatal error after updating to toc_api:^2 Active .

  • 🇨🇦Canada joseph.olstad

    We should close this when the upstream toc_filter patch is committed/resolved/fixed.

  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Thanks all. Committed. 🍻

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 26 days ago
  • 🇨🇭Switzerland phma Basel, CH

    I updated to the latest version of toc_filter, and I'm still getting the exact same error. Am I missing something?

    TypeError: Drupal\toc_api\Plugin\Block\TocBlockBase::getCurrentToc(): Return value must be of type Drupal\toc_api\TocInterface, null returned in Drupal\toc_api\Plugin\Block\TocBlockBase->getCurrentToc() (line 109 of modules/contrib/toc_api/src/Plugin/Block/TocBlockBase.php).
    Drupal\toc_api\Plugin\Block\TocBlockBase->build() (Line: 106)
    Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender(Object, 'section_component.build.render_array', Object)
    call_user_func(Array, Object, 'section_component.build.render_array', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'section_component.build.render_array') (Line: 90)
    Drupal\layout_builder\SectionComponent->toRenderArray(Array, 1) (Line: 88)
    Drupal\layout_builder\Section->toRenderArray(Array, 1) (Line: 228)
    Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection(Object, 0) (Line: 112)
    Drupal\layout_builder\Element\LayoutBuilder->layout(Object) (Line: 86)
    Drupal\layout_builder\Element\LayoutBuilder->preRender(Array)
    call_user_func_array(Array, Array) (Line: 113)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, 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: 875)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 504)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • 🇨🇦Canada joseph.olstad

    double check your composer.lock for drupal/toc_filter:2.4

    drush pml | grep toc

  • 🇨🇭Switzerland phma Basel, CH

    Correct me if I'm wrong, but I this seems to be a separate issue to #3518549

    getToc in TocManager.php can return NULL. But this case isn't handled properly in TocBlockBase.php.

      /**
       * {@inheritdoc}
       */
      public function getToc(string $id): ?TocInterface {
        return (isset($this->tocs[$id])) ? $this->tocs[$id] : NULL;
      }
    

    I can create a patch, but should we reopen this issue, as it isn't really fixed in my opinion?

  • 🇨🇭Switzerland phma Basel, CH

    Correct me if I'm wrong, but I this seems to be a separate issue to 🐛 Fatal error after updating to toc_api:^2 Active

    getToc in TocManager.php can return NULL. But this case isn't handled properly in TocBlockBase.php.

      /**
       * {@inheritdoc}
       */
      public function getToc(string $id): ?TocInterface {
        return (isset($this->tocs[$id])) ? $this->tocs[$id] : NULL;
      }
    

    I can create a patch, but should we reopen this issue, as it isn't really fixed in my opinion?

  • 🇨🇦Canada joseph.olstad

    as per comment #14

  • 🇪🇸Spain fjgarlin

    I agree that this is not the same as 🐛 Fatal error after updating to toc_api:^2 Active .

    This issue belongs to this queue and. can be fixed as suggested in #14.

  • @phma opened merge request.
  • 🇨🇭Switzerland phma Basel, CH
Production build 0.71.5 2024