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.

Issue fork toc_api-3520464

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

finex created an issue. See original summary.

joseph.olstad’s picture

I will review merge requests and or related patches.

joseph.olstad’s picture

Status: Active » Reviewed & tested by the community

Please apply the upstream patch!

liam morland’s picture

What is the patch that needs to be applied?

liam morland’s picture

Unless I am misunderstanding something, this should be closed as duplicate of #3518549: Make TocFilterBlock::blockAccess() return type be compatible with parent.

joseph.olstad’s picture

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

joseph.olstad’s picture

vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all. Committed. 🍻

joseph.olstad’s picture

Thank you!

Status: Fixed » Closed (fixed)

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

phma’s picture

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)
joseph.olstad’s picture

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

drush pml | grep toc

rebuild cache, and sometimes need to restart php service if you've got greedy opcode cache / apcu.

phma’s picture

Correct me if I'm wrong, but I this seems to be a separate issue to #3518549: Make TocFilterBlock::blockAccess() return type be compatible with parent

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?

phma’s picture

It duplicated my comment, when I tried to edit it, sorry.

joseph.olstad’s picture

Status: Closed (fixed) » Active

as per comment #14

fjgarlin’s picture

I agree that this is not the same as #3518549: Make TocFilterBlock::blockAccess() return type be compatible with parent.

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

phma’s picture

Status: Active » Needs review
joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs review » Fixed
joseph.olstad’s picture

Status: Fixed » Closed (fixed)

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

joseph.olstad’s picture

Please upgrade to 2.0.1-rc1 and let me know how it works out for you. I won't tag 2.0.1 until I get at least some statistics on usage or some kind of feedback.