diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index de04bdc..c3d92a5 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -38,7 +38,7 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N */ public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) { $build = array(); - foreach ($entities as $key => $entity) { + foreach ($entities as $entity) { $entity_id = $entity->id(); $plugin = $entity->getPlugin(); $plugin_id = $plugin->getPluginId(); @@ -63,6 +63,8 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la '#base_plugin_id' => $base_id, '#derivative_plugin_id' => $derivative_id, '#id' => $entity->id(), + // Add the entity so that it can be used in the #pre_render method. + '#block' => $entity, ); $build[$entity_id]['#configuration']['label'] = String::checkPlain($configuration['label']); @@ -99,9 +101,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $build[$entity_id] = $this->buildBlock($build[$entity_id]); } - // @todo Remove after fixing http://drupal.org/node/1989568. - $build[$key]['#block'] = $entity; - // Don't run in ::buildBlock() to ensure cache keys can be altered. If an // alter hook wants to modify the block contents, it can append another // #pre_render hook. @@ -121,6 +120,9 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la */ public function buildBlock($build) { $content = $build['#block']->getPlugin()->build(); + // Remove the block entity from the render array, to ensure that blocks + // can be rendered without the block config entity. + unset($build['#block']); if (!empty($content)) { // Place the $content returned by the block plugin into a 'content' child // element, as a way to allow the plugin to have complete control of its diff --git a/core/modules/block/src/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/src/Tests/BlockTemplateSuggestionsUnitTest.php index 604b1a7..a3f77b4 100644 --- a/core/modules/block/src/Tests/BlockTemplateSuggestionsUnitTest.php +++ b/core/modules/block/src/Tests/BlockTemplateSuggestionsUnitTest.php @@ -44,10 +44,10 @@ function testBlockThemeHookSuggestions() { )); $variables = array(); - $variables['elements']['#block'] = $block; $plugin = $block->getPlugin(); $variables['elements']['#configuration'] = $plugin->getConfiguration(); $variables['elements']['#plugin_id'] = $plugin->getPluginId(); + $variables['elements']['#id'] = $block->id(); $variables['elements']['#base_plugin_id'] = $plugin->getBasePluginId(); $variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId(); $variables['elements']['content'] = array();