diff --git a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
index 20fbb61..3d26665 100644
--- a/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
+++ b/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
@@ -3,6 +3,7 @@
namespace Drupal\panels\Plugin\DisplayBuilder;
use Drupal\Component\Utility\Html;
+use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -102,60 +103,69 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI
*/
protected function buildRegions(array $regions, array $contexts) {
$build = [];
+ /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
foreach ($regions as $region => $blocks) {
if (!$blocks) {
continue;
}
- $region_name = Html::getClass("block-region-$region");
- $build[$region]['#prefix'] = '
';
- $build[$region]['#suffix'] = '
';
-
- /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
$weight = 0;
+
+ $build[$region]['#prefix'] = '';
+ $build[$region]['#suffix'] = '
';
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();
$this->moduleHandler->alter(['block_build', 'block_build_' . $block->getBaseId()], $content, $block);
- 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;
+ }
$this->moduleHandler->alter(['block_view', 'block_view_' . $block->getBaseId()], $block_render_array, $block);
$build[$region][$block_id] = $block_render_array;