diff --git a/core/modules/block/block.module b/core/modules/block/block.module index ec639b0..5cb5a4f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -311,21 +311,20 @@ function _block_get_renderable_region($list = array()) { !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')); foreach ($list as $key => $block) { - $build[$key] = array( - '#block' => $block, - '#weight' => $block->get('weight'), - '#theme_wrappers' => array('block'), - ); if ($not_cacheable || in_array($block->get('cache'), array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { - // Non-cached blocks get built immediately. Provides more content - // that can be easily manipulated during hook_page_alter(). - $build[$key] = _block_get_renderable_block($build[$key]); + // Non-cached blocks get built immediately. + if ($block->access()) { + $build[$key] = entity_view($block, 'full'); + } } else { $key_components = explode('.', $key); $id = array_pop($key_components); - $build[$key] += array( + $build[$key] = array( + '#block' => $block, + '#weight' => $block->get('weight'), + '#theme_wrappers' => array('block'), '#pre_render' => array('_block_get_renderable_block'), '#cache' => array( 'keys' => array($id, $block->get('module')), @@ -342,7 +341,7 @@ function _block_get_renderable_region($list = array()) { // to perform contextual actions on the help block, and the links needlessly // draw attention on it. if (!in_array($block->get('plugin'), array('system_help_block', 'system_main_block'))) { - $build[$key]['#contextual_links']['block'] = array('admin/structure/block', array($key)); + $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($key)); } } return $build; @@ -408,28 +407,23 @@ function block_themes_enabled($theme_list) { */ function block_theme_initialize($theme) { // Initialize theme's blocks if none already registered. - $has_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); + $has_blocks = entity_load_multiple_by_properties('block', array('theme' => $theme)); if (!$has_blocks) { $default_theme = variable_get('theme_default', 'stark'); // Apply only to new theme's visible regions. $regions = system_region_list($theme, REGIONS_VISIBLE); - $default_theme_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme); - foreach ($default_theme_blocks as $config_id) { - $block_config = config($config_id)->get(); - $machine_name = explode('.', $config_id); - $machine_name = array_pop($machine_name); - $new_config_id = 'plugin.core.block.' . $theme . '.' . $machine_name; - $new_block = config($new_config_id); + $default_theme_blocks = entity_load_multiple_by_properties('block', array('theme' => $default_theme)); + foreach ($default_theme_blocks as $default_theme_block_id => $default_theme_block) { + list(, $machine_name) = explode('.', $default_theme_block_id); + $block = $default_theme_block->createDuplicate(); + $block->set('id', $theme . '.' . $machine_name); + $block->set('theme', $theme); // If the region isn't supported by the theme, assign the block to the // theme's default region. - if (!isset($regions[$block_config['region']])) { - $new_block->set('region', system_default_region($theme)); - unset($block_config['region']); - } - foreach ($block_config as $key => $value) { - $new_block->set($key, $value); + if (!isset($regions[$block->get('region')])) { + $block->set('region', system_default_region($theme)); } - $new_block->save(); + $block->save(); } } } @@ -480,17 +474,7 @@ function _block_get_renderable_block($element) { $block = $element['#block']; // Don't bother to build blocks that aren't accessible. if ($element['#access'] = $block->access()) { - $build = $block->build(); - if ($build) { - if (isset($build['#title'])) { - $element['#title'] = $build['#title']; - } - $element += $build; - } - else { - // @todo Add an inline comment explaining why this line is necessary. - $element = array(); - } + $element += entity_view($block, 'full'); } return $element; } @@ -534,7 +518,10 @@ function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); $block = $variables['elements']['#block']; $variables['block'] = (object) $block->getDefinition(); - if ($label = $block->label()) { + if (!empty($variables['block']->label)) { + $variables['block']->subject = $variables['block']->label; + } + elseif ($label = $block->label()) { $variables['block']->subject = $label; } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php index bfe5dcc..30d35f5 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php @@ -29,17 +29,6 @@ class CustomBlock extends BlockBase { /** - * Overrides \Drupal\block\BlockBase::blockSettings(). - */ - public function blockSettings() { - // By default, use a blank block title rather than the block description - // (which is "Custom Block"). - return array( - 'subject' => '', - ); - } - - /** * Overrides \Drupal\block\BlockBase::getConfig(). */ public function getConfig() { @@ -94,7 +83,7 @@ public function blockSubmit($form, &$form_state) { 'bid' => is_numeric($bid) ? $bid : NULL, ); drupal_write_record('block_custom', $block, !is_null($block['bid']) ? array('bid') : array()); - $this->configuration['id'] = 'custom_block:' . $block['bid']; + $form_state['entity']->set('plugin', 'custom_block:' . $block['bid']); // Invalidate the block cache to update custom block-based derivatives. if (module_exists('block')) { drupal_container()->get('plugin.manager.block')->clearCachedDefinitions(); @@ -106,6 +95,7 @@ public function blockSubmit($form, &$form_state) { */ public function blockBuild() { // Populate the block with the user-defined block body. + $this->getConfig(); return array( '#theme' => 'custom_block_block', '#body' => $this->configuration['body'], diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php new file mode 100644 index 0000000..dd2ee22 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -0,0 +1,52 @@ +viewMultiple(array($entity), $view_mode, $langcode); + return reset($build); + } + + /** + * Implements Drupal\Core\Entity\EntityRenderControllerInterface::viewMultiple(). + */ + public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) { + $build = array(); + foreach ($entities as $entity_id => $entity) { + $build[$entity_id] = array( + '#block' => $entity, + '#weight' => $entity->get('weight'), + '#theme_wrappers' => array('block'), + ) + $entity->getPlugin()->blockBuild(); + + $id = str_replace(':', '__', $entity->get('plugin')); + list(, $name) = $entity->id(); + drupal_alter(array('block_view', "block_view_$id", "block_view_$name"), $build[$entity_id], $entity); + } + return $build; + } + +} diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php index f23588d..c457008 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -20,6 +20,7 @@ * module = "block", * controller_class = "Drupal\block\BlockStorageController", * access_controller_class = "Drupal\block\BlockAccessController", + * render_controller_class = "Drupal\block\BlockRenderController", * form_controller_class = { * "default" = "Drupal\block\BlockFormController" * }, @@ -187,34 +188,4 @@ public function getExportProperties() { return $properties; } - /** - * Implements \Drupal\block\BlockInterface::build(). - * - * Allows blocks to be altered after they are built. - * - * Most block plugins should not override this method. To define how a - * particular block is rendered, implement the abstract method - * BlockBase::blockBuild(). - * - * @return array $build - * A renderable array of data. - * - #title: The default localized title of the block. - * - * @todo Add specific examples of $id and $name below. - * - * @see \Drupal\block\BlockBase::blockBuild() - */ - public function build() { - // Allow modules to modify the block before it is viewed, via either - // hook_block_view_alter(), hook_block_view_ID_alter(), or - // hook_block_view_NAME_alter(). - $id = str_replace(':', '__', $this->getPlugin()->getPluginId()); - - $name = ''; - - $build = $this->getPlugin()->blockBuild(); - drupal_alter(array('block_view', "block_view_$id", "block_view_$name"), $build, $this); - return $build; - } - } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index ba0ca9a..5ff4cdf 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -118,7 +118,7 @@ public function testCustomBlock() { $this->assertText(t('The block configuration has been saved.'), 'Custom block successfully created.'); // Check that block_block_view() returns the correct title and content. - $data = $block->build(); + $data = entity_view($block, 'full'); $this->assertEqual(check_markup($custom_block['body[value]'], $block->get('format')), render($data), 'BlockInterface::build() provides correct block content.'); // Check whether the block can be moved to all available regions. diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index fd5b5df..5515387 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -482,7 +482,7 @@ function menu_reset_item($link) { */ function menu_block_view_alter(&$build, $block) { // Add contextual links for system menu blocks. - if ($block instanceof SystemMenuBlock) { + if ($block->getPlugin() instanceof SystemMenuBlock) { foreach (element_children($build) as $key) { $build['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($build[$key]['#original_link']['menu_name'])); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php index 296212c..6d74ee4 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php @@ -74,7 +74,7 @@ public function blockForm($form, &$form_state) { public function blockBuild() { $output = $this->view->executeDisplay($this->displayID); // Set the subject to the title configured in the view. - $this->configuration['subject'] = filter_xss_admin($this->view->getTitle()); + $this->configuration['label'] = filter_xss_admin($this->view->getTitle()); // Before returning the block output, convert it to a renderable array // with contextual links. views_add_block_contextual_links($output, $this->view, $this->displayID);