diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index c573d10..4863a56 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -115,7 +115,7 @@ function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_r $form['#tree'] = TRUE; foreach ($blocks as $key => $instance) { - $info = $instance->getDefinition(); + $info = $instance->getPlugin()->getDefinition(); $form['blocks'][$key]['info'] = array( '#markup' => check_plain($info['subject']), ); @@ -226,8 +226,8 @@ function _block_compare($a, $b) { } } // Sort by title. - $ainfo = $a->getDefinition(); - $binfo = $b->getDefinition(); + $ainfo = $a->getPlugin()->getDefinition(); + $binfo = $b->getPlugin()->getDefinition(); return strcmp($ainfo['subject'], $binfo['subject']); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 5cb5a4f..5770531 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -517,7 +517,8 @@ function block_rebuild() { function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); $block = $variables['elements']['#block']; - $variables['block'] = (object) $block->getDefinition(); + $variables['block'] = (object) $block->getPlugin()->getDefinition(); + $variables['block']->region = $block->get('region'); if (!empty($variables['block']->label)) { $variables['block']->subject = $variables['block']->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 30d35f5..3113bfe 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 @@ -95,7 +95,6 @@ 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/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index 79e3b38..bf28b0f 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -19,7 +19,7 @@ class BlockFormController extends EntityFormController { * Overrides \Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $entity) { - $definition = $entity->getDefinition(); + $definition = $entity->getPlugin()->getDefinition(); $form['module'] = array( '#type' => 'value', '#value' => $definition['module'], diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php index dd2ee22..ae314a0 100644 --- a/core/modules/block/lib/Drupal/block/BlockRenderController.php +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -36,11 +36,15 @@ 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 $entity_id => $entity) { - $build[$entity_id] = array( - '#block' => $entity, - '#weight' => $entity->get('weight'), - '#theme_wrappers' => array('block'), - ) + $entity->getPlugin()->blockBuild(); + $build[$entity_id] = array(); + if ($view_mode == 'full') { + $build[$entity_id] += array( + '#block' => $entity, + '#weight' => $entity->get('weight'), + '#theme_wrappers' => array('block'), + ); + } + $build[$entity_id] += $entity->getPlugin()->blockBuild(); $id = str_replace(':', '__', $entity->get('plugin')); list(, $name) = $entity->id(); diff --git a/core/modules/block/lib/Drupal/block/BlockStorageController.php b/core/modules/block/lib/Drupal/block/BlockStorageController.php index 73d132f..76676dc 100644 --- a/core/modules/block/lib/Drupal/block/BlockStorageController.php +++ b/core/modules/block/lib/Drupal/block/BlockStorageController.php @@ -8,6 +8,7 @@ namespace Drupal\block; use Drupal\Core\Config\Entity\ConfigStorageController; +use Drupal\Core\Entity\EntityInterface; /** * Defines the storage controller class for Block entities. @@ -27,4 +28,17 @@ public function loadByProperties(array $values = array()) { return $blocks; } + /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::loadByProperties(). + */ + protected function preSave(EntityInterface $entity) { + parent::preSave($entity); + + // Cache settings are stored directly on the block, remove them from + // configuration. + $configuration = $entity->get('configuration'); + unset($configuration['cache']); + $entity->set('configuration', $configuration); + } + } 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 c457008..572d5e1 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 @@ -133,7 +133,11 @@ public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); $this->instance = drupal_container()->get('plugin.manager.block')->createInstance($this->plugin, $this->configuration); - $this->configuration += $this->instance->blockSettings(); + $this->configuration += $this->instance->getConfig(); + + if (isset($this->configuration['cache'])) { + $this->cache = $this->configuration['cache']; + } if (!isset($this->theme) && $id = $this->id()) { list($this->theme) = explode('.', $id); @@ -141,19 +145,6 @@ public function __construct(array $values, $entity_type) { } /** - * Returns the full definition of this block. - * - * @return array - * Return an array containing the plugin's configuration, the plugin's - * definition, and this block's properties. - * - * @todo This is overkill. Remove or reduce this as much as possible. - */ - public function getDefinition() { - return $this->instance->getConfig() + $this->instance->getDefinition() + $this->getExportProperties(); - } - - /** * Returns the plugin instance. * * @return \Drupal\block\BlockInterface diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 5ff4cdf..fdaef07 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -118,8 +118,10 @@ 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 = entity_view($block, 'full'); - $this->assertEqual(check_markup($custom_block['body[value]'], $block->get('format')), render($data), 'BlockInterface::build() provides correct block content.'); + $data = entity_view($block, 'teaser'); + $definition = $block->getPlugin()->getDefinition(); + $config = $definition['settings']; + $this->assertEqual(check_markup($custom_block['body[value]'], $config['format']), render($data), 'BlockInterface::build() provides correct block content.'); // Check whether the block can be moved to all available regions. $custom_block['module'] = 'block'; diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php index 5be3aa3..cc96397 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php @@ -81,7 +81,7 @@ function testUserLoginBlock() { */ function testWhosOnlineBlock() { $block = entity_load('block', 'stark.online'); - $config = $block->getDefinition(); + $config = $block->get('configuration'); // Generate users. $user1 = $this->drupalCreateUser(array()); @@ -99,7 +99,7 @@ function testWhosOnlineBlock() { $this->updateAccess($this->adminUser->uid, $inactive_time); // Test block output. - $content = $block->build(); + $content = entity_view($block, 'full'); $this->drupalSetContent(render($content)); $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).'); $this->assertText($user1->name, 'Active user 1 found in online list.');