diff --git a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php index 5ba0952..d24f966 100644 --- a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php +++ b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php @@ -2,6 +2,7 @@ namespace Drupal\panels\Plugin\DisplayBuilder; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -117,33 +118,36 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI '#derivative_plugin_id' => $block->getDerivativeId(), ]; - // Build the block and bubble its attributes up if possible. This - // allows modules like Quickedit to function. - // See \Drupal\block\BlockViewBuilder::preRender() for reference. $content = $block->build(); - if ($content !== NULL && !Element::isEmpty($content)) { + if (!is_array($content)) { + throw new \LogicException(new FormattableMarkup('Block %block build method has to return an array.', ['%block' => $block_id])); + } + + // If the block is not empty, build the block and bubble its + // attributes up if possible. This allows modules like Quickedit to + // function. + // 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. + // @see \Drupal\block\BlockViewBuilder::preRender() + if (!Element::isEmpty($content)) { foreach (['#attributes', '#contextual_links'] as $property) { if (isset($content[$property])) { $block_render_array[$property] += $content[$property]; unset($content[$property]); } } + $block_render_array['content'] = $content; } - - // 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)) { + else { $block_render_array = []; $cacheable_metadata = CacheableMetadata::createFromObject($block_render_array); $cacheable_metadata->applyTo($block_render_array); if (isset($content['#cache'])) { - $block_render_array += $content['#cache']; + $block_render_array['#cache'] = $content['#cache']; } } - $block_render_array['content'] = $content; - $build[$region][$block_id] = $block_render_array; } }