A call to {{ drupal_block('contact_block') }}inside a Twig template causes the following error:

TypeError: Argument 1 passed to Drupal\Core\Render\Element::isEmpty() must be of the type array, null given, called in /web/modules/contrib/twig_tweak/src/TwigExtension.php on line 168 in Drupal\Core\Render\Element::isEmpty() (line 198 of /Users/drauta/Sites/devdesktop/webiblio_d8/web/core/lib/Drupal/Core/Render/Element.php)

This error showed up just after upgrading drupal core from 8.7.9 to 8.8.1 (PHP 7.2). It breaks in both anonymous and logged in users.

CommentFileSizeAuthor
#2 typerror_drupalblock_3108210.patch499 bytesrcodina

Issue fork twig_tweak-3108210

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

rcodina created an issue. See original summary.

rcodina’s picture

Status: Active » Needs review
StatusFileSize
new499 bytes
rcodina’s picture

Issue summary: View changes
chi’s picture

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

Under unknown circumstances the following error shows up

This needs steps to reproduce.

rcodina’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review

I updated the main description of the issue.

rcodina’s picture

The problem is that for some reason $block_plugin->build() inside TwigExtension::drupalBlock is returning NULL for some reason. Given that PHP fatally breaks if the parameter of isEmpty is not an array, I think it would be nice to apply this patch to nicely break without breaking the whole page (even if we cannot reproduce it in a clean Drupal site).

chi’s picture

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

Do you use contact_block module?
I've just installed it and tested on Drupal 8.9. Everything works fine.

$block_plugin->build() inside TwigExtension::drupalBlock is returning NULL for some reason

BlockPluginInterface::build is always supposed to return array.

chi’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
b-prod’s picture

Status: Closed (cannot reproduce) » Reviewed & tested by the community

To reproduce:
Create a view with an exposed filter, expose it to a block, add the block to a page, then remove the exposed filter from the view.

You get the described error, as the $build['content'] is NULL, and a PHP fatal error...

chi’s picture

Thank you. I've managed to reproduce it now. That's actually duplicates #3212340: drupal_block() show fatal error if block plugin return NULL. Under some circumstances ViewsExposedFilterBlock::build() returns NULL though it is supposed to return array per interface declaration. So it's a bug in Drupal Core. I've just submitted a bug report for this #3230681: ViewsExposedFilterBlock::build must always return array.

chi’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

The patch in #3212340: drupal_block() show fatal error if block plugin return NULL was not backported to 2.x. The provided here patch offers same fix but needs reroll.

chi’s picture

Category: Bug report » Task

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

This appears to not be needed for the 3.x branch? Should it be added to the 2.x branch though?

chi’s picture

@smustgrave, it should.

rpayanm made their first commit to this issue’s fork.

rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
chi’s picture

Status: Needs review » Fixed

Thank you.

Status: Fixed » Closed (fixed)

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