diff --git a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
index 73938cd..86fc0df 100644
--- a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
+++ b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
@@ -1,23 +1,16 @@
$blocks) {
if (!$blocks) {
continue;
}
- $region_name = Html::getClass("block-region-$region");
- $build[$region]['#prefix'] = '
';
+ $weight = 0;
+
+ $build[$region]['#prefix'] = '
';
$build[$region]['#suffix'] = '
';
- /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
- $weight = 0;
foreach ($blocks as $block_id => $block) {
if ($block instanceof ContextAwarePluginInterface) {
$this->contextHandler->applyContextMapping($block, $contexts);
}
+
if ($block->access($this->account)) {
- $block_render_array = [
- '#theme' => 'block',
- '#attributes' => [],
- '#contextual_links' => [],
- '#weight' => $weight++,
- '#configuration' => $block->getConfiguration(),
- '#plugin_id' => $block->getPluginId(),
- '#base_plugin_id' => $block->getBaseId(),
- '#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)) {
- foreach (['#attributes', '#contextual_links'] as $property) {
- if (isset($content[$property])) {
- $block_render_array[$property] += $content[$property];
- unset($content[$property]);
- }
- }
+
+ if (!is_array($content)) {
+ throw new \LogicException(sprintf(
+ '%s::build() method has to return an array. Class returning non-array value is: %s',
+ BlockPluginInterface::class,
+ get_class($block)
+ ));
}
// 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)) {
$block_render_array = [];
$cacheable_metadata = CacheableMetadata::createFromObject($block_render_array);
$cacheable_metadata->applyTo($block_render_array);
if (isset($content['#cache'])) {
- $block_render_array['#cache'] += $content['#cache'];
+ $block_render_array['#cache'] = $content['#cache'];
}
}
+ else {
+ $block_render_array = [
+ '#theme' => 'block',
+ '#attributes' => [],
+ '#contextual_links' => [],
+ '#weight' => $weight++,
+ '#configuration' => $block->getConfiguration(),
+ '#plugin_id' => $block->getPluginId(),
+ '#base_plugin_id' => $block->getBaseId(),
+ '#derivative_plugin_id' => $block->getDerivativeId(),
+ ];
+
+ // If the block is not empty, build the block and bubble its
+ // attributes up if possible. This allows modules like Quickedit to
+ // function.
+ foreach (['#attributes', '#contextual_links'] as $property) {
+ if (isset($content[$property])) {
+ $block_render_array[$property] += $content[$property];
+ unset($content[$property]);
+ }
+ }
- $block_render_array['content'] = $content;
+ $block_render_array['content'] = $content;
+ }
$build[$region][$block_id] = $block_render_array;
}