Call to a member function getRegion() on null in theme_suggestions_block_alter()

Created on 24 April 2024, 5 months ago

Problem/Motivation

When using the Block_ajax module in conjunction with the Kiso theme, there's an incompatibility issue where the block fails to load due to the block ID passed in the variables being in the format block_content: instead of the expected block configuration ID. This occurs because Kiso attempts to load the block during hook_preprocess_block() and theme_suggestions_block_alter() to determine the block region to create some theme suggestions.

Steps to reproduce

  1. Install Kiso theme.
  2. Enable block_ajax module.
  3. Enable block_content module
  4. Create a new block_content entity
  5. Place the block_content as Ajax block in the block layout
  6. Observe the failure to load the block due to the incorrect block ID format.

Proposed resolution

We should add the $block_id value in $configuration['id'] key before we call the instruction $blockInstance = $this->blockViewBuilder->build($plugin_id, $configuration, TRUE); in the loadBlock() method of AjaxBlockController.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium bernardopaulino Brussels

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

Comments & Activities

  • Issue created by @bernardopaulino
  • Status changed to Needs review 4 days ago
  • 🇵🇹Portugal rutiolma

    This issue was based on Kiso theme but this will affect any theme with a preprocess block that tries to do a Block::load().
    As mentioned in the issue description, if we don't pass the $block_id to the $configuration argument, then Block::load() will be done on the plugin id.

    I'm proposing a simple patch.
    Tests missing

Production build 0.71.5 2024