Incorrect logic inside of StandardDisplayBuilder could lead to fatal error (followup for #2781897)

Created on 5 October 2016, about 8 years ago
Updated 7 July 2023, over 1 year ago

Current implementation of Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder::buildRegions() has a wrong condition which could lead to TypeError (null instead of expected array) in \Drupal\Core\Render\Element::isEmpty().

Example:

          $content = $block->build();
          if ($content !== NULL && !Element::isEmpty($content)) {
            foreach (['#attributes', '#contextual_links'] as $property) {
              if (isset($content[$property])) {
                $block_render_array[$property] += $content[$property];
                unset($content[$property]);
              }
            }
          }

          // If the block is empty, instead of trying to render the block
          // correctly return just #cache, so that the render system knows the
          // reasons (cache contexts & tags) why this block is empty.
          if (Element::isEmpty($content)) {

The Element::isEmpty($content) on second execution fails with fatal error when $content contains null.

Steps to reproduce described in #2819219: Fatal error when "setMainContent()" method is not called (block module not installed) .

@capuleto #8:

This patch also makes Drupal\Core\Render\Element::children() trigger several warnings like

"max-age" is an invalid render array key

@Devin Carlson #9:

This also doesn't check if $content !== NULL, as is done earlier in the function, which causes a fatal error if $content is NULL.

Recoverable fatal error: Argument 1 passed to Drupal\Core\Render\Element::isEmpty() must be of the type array, null given called in panels/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php on line 136.

🐛 Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

🇫🇮Finland lauriii Finland

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024