Problem/Motivation

Some blocks plugins return NULL in build() method, eg \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock::build(). Because of this, an fatal error:

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

Text error from 2.x version

Steps to reproduce

1. Create block plugin with:

public function build() {
  return NULL;
}

2. Add in twig file:

{{ drupal_block('block_with_null') }}

CommentFileSizeAuthor
#2 3212340_1.patch553 bytesxandeadx

Comments

xandeadx created an issue. See original summary.

xandeadx’s picture

StatusFileSize
new553 bytes
xandeadx’s picture

Issue summary: View changes
chi’s picture

Category: Bug report » Task

That's a bug in Aggegator module. The build() method should always return an array per BlockPluginInterface declaration.

  • Chi committed c336ca8 on 3.x authored by xandeadx
    Issue #3212340 by xandeadx: drupal_block() show fatal error if block...
chi’s picture

Status: Needs review » Fixed
Related issues: +#3212354: AggregatorFeedBlock::build must always return array

Thank you.

Status: Fixed » Closed (fixed)

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