diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php index 4c2df27..d281731 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides an 'Aggregator category' block for the latest items in a category. @@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $id = $this->getPluginId(); if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) { $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid)); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php index e902eb5..528c7db 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides an 'Aggregator feed' block with the latest items from the feed. @@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { // Plugin IDs look something like this: aggregator_feed_block:1. list(, $id) = explode(':', $this->getPluginId()); if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) { 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 6f7be2e..e09a3ab 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 @@ -9,6 +9,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Defines a generic custom block type. @@ -107,7 +108,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { // Populate the block with the user-defined block body. return array( '#theme' => 'custom_block_block', diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index b9a149f..4e29b74 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -8,6 +8,7 @@ namespace Drupal\block; use Drupal\Component\Plugin\PluginBase; +use Drupal\block\Plugin\Core\Entity\Block; /** * Defines a base block implementation that most blocks plugins will extend. diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index 3d2d29b..305261c 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -36,7 +36,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { '#type' => 'textfield', '#title' => t('Block title'), '#maxlength' => 255, - '#default_value' => $entity->label(), + '#default_value' => !$entity->isNew() ? $entity->label() : $definition['subject'], ); $form['settings']['machine_name'] = array( '#type' => 'textfield', diff --git a/core/modules/block/lib/Drupal/block/BlockInterface.php b/core/modules/block/lib/Drupal/block/BlockInterface.php index 602efce..7946716 100644 --- a/core/modules/block/lib/Drupal/block/BlockInterface.php +++ b/core/modules/block/lib/Drupal/block/BlockInterface.php @@ -6,6 +6,8 @@ namespace Drupal\block; +use Drupal\block\Plugin\Core\Entity\Block; + /** * Defines the required interface for all block plugins. * @@ -31,11 +33,14 @@ public function blockSettings(); /** - * Builds and returns the renderable array for this block. + * Builds and returns the renderable array for this block plugin. + * + * @param \Drupal\block\Plugin\Core\Entity\Block $entity + * The block entity containing this plugin. * * @return array - * A renderable array representing the output of the block. + * A renderable array representing the content of the block. */ - public function blockBuild(); + public function blockBuild(Block $entity); } diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php index 4ecb2a1..ef373d6 100644 --- a/core/modules/block/lib/Drupal/block/BlockRenderController.php +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -45,7 +45,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco return array(); } - $defaults = array( + return array( '#block' => $entity, '#weight' => $entity->get('weight'), '#theme_wrappers' => array('block'), @@ -53,19 +53,9 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langco 'id' => $entity->get('plugin'), 'region' => $entity->get('region'), 'module' => $entity->get('module'), + 'subject' => $entity->label(), ), ); - $defaults['#block_config'] += $entity->getPlugin()->getConfig(); - - // @todo This is a hold-over from the old behavior, it is crazy. - if (!empty($defaults['#block_config']['label'])) { - $defaults['#block_config']['subject'] = $defaults['#block_config']['label']; - } - elseif ($label = $entity->label()) { - $defaults['#block_config']['subject'] = $label; - } - - return $defaults; } /** @@ -82,7 +72,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 $entity_id => $entity) { - $build[$entity_id] = $entity->getPlugin()->blockBuild(); + $build[$entity_id] = $entity->getPlugin()->blockBuild($entity); // Allow blocks to be empty, do not add in the defaults. if (!empty($build[$entity_id])) { $build[$entity_id] = $this->getBuildDefaults($entity, $view_mode, $langcode) + $build[$entity_id]; diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index b1cc516..ad1229a 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -8,7 +8,7 @@ namespace Drupal\block\Tests; use Drupal\simpletest\DrupalUnitTestBase; -use Drupal\system\Plugin\block\block\SystemPoweredByBlock; +use Drupal\block_test\Plugin\block\block\TestHtmlIdBlock; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\block\BlockStorageController; use Drupal\Core\Entity\EntityMalformedException; @@ -26,7 +26,7 @@ class BlockStorageUnitTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system'); + public static $modules = array('block_test'); /** * The block storage controller. @@ -78,44 +78,44 @@ protected function createTests() { // Create a block with only required values. $entity = $this->controller->create(array( - 'id' => 'stark.powered', - 'plugin' => 'system_powered_by_block', + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', )); $entity->save(); $this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.'); // Verify all of the block properties. - $actual_properties = config('plugin.core.block.stark.powered')->get(); + $actual_properties = config('plugin.core.block.stark.test_block')->get(); $this->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.'); unset($actual_properties['uuid']); // Ensure that default values are filled in. $expected_properties = array( - 'id' => 'stark.powered', + 'id' => 'stark.test_block', 'label' => '', 'region' => '-1', 'weight' => '', - 'cache' => '-1', - 'module' => 'system', + 'cache' => '1', + 'module' => 'block_test', 'theme' => 'stark', 'status' => '1', 'visibility' => array(), - 'plugin' => 'system_powered_by_block', + 'plugin' => 'test_html_id', 'configuration' => array( - 'subject' => t('Powered by Drupal'), + 'subject' => t('Test block html id'), ), ); $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.'); - $this->assertTrue($entity->getPlugin() instanceof SystemPoweredByBlock, 'The entity has an instance of the correct block plugin.'); + $this->assertTrue($entity->getPlugin() instanceof TestHtmlIdBlock, 'The entity has an instance of the correct block plugin.'); } /** * Tests the rendering of blocks. */ protected function loadTests() { - $entities = $this->controller->load(array('stark.powered')); + $entities = $this->controller->load(array('stark.test_block')); $entity = reset($entities); $this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.'); @@ -124,7 +124,7 @@ protected function loadTests() { $this->assertEqual($entity->get('region'), '-1'); $this->assertTrue($entity->get('status')); $this->assertEqual($entity->get('theme'), 'stark'); - $this->assertEqual($entity->get('module'), 'system'); + $this->assertEqual($entity->get('module'), 'block_test'); $this->assertTrue($entity->uuid()); } @@ -133,23 +133,23 @@ protected function loadTests() { */ protected function renderTests() { $entity = $this->controller->create(array( - 'id' => 'stark.powered', - 'plugin' => 'system_powered_by_block', + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', )); // Test the rendering of a block. $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; + $expected[] = '
'; $expected[] = ''; - $expected[] = '

Powered by Drupal

'; + $expected[] = '

Test block html id

'; $expected[] = ' '; $expected[] = '
'; - $expected[] = ' Powered by Drupal
'; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(render($output), $expected_output, 'The block rendered correctly.'); + $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.'); // Reset the HTML IDs so that the next render is not affected. drupal_static_reset('drupal_html_id'); @@ -158,23 +158,23 @@ protected function renderTests() { $entity->set('label', 'Powered by Bananas'); $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; + $expected[] = '
'; $expected[] = ''; $expected[] = '

Powered by Bananas

'; $expected[] = ' '; $expected[] = '
'; - $expected[] = ' Powered by Drupal
'; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(render($output), $expected_output, 'The block rendered correctly.'); + $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.'); } /** * Tests the deleting of blocks. */ protected function deleteTests() { - $entities = $this->controller->load(array('stark.powered')); + $entities = $this->controller->load(array('stark.test_block')); $entity = reset($entities); // Ensure that the storage isn't currently empty. @@ -197,12 +197,12 @@ public function testDefaultBlocks() { $entities = $this->controller->load(); $this->assertTrue(empty($entities), 'There are no blocks initially.'); - // Enable the Help module, which provides a default block. - $this->enableModules(array('help')); + // Install the block_test.module, so that its default config is installed. + $this->enableModules(array('block_test')); $entities = $this->controller->load(); $entity = reset($entities); - $this->assertEqual($entity->id(), 'seven.help', 'The default help block was loaded.'); + $this->assertEqual($entity->id(), 'stark.test_block', 'The default test block was loaded.'); } } diff --git a/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml b/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml new file mode 100644 index 0000000..dacfb64 --- /dev/null +++ b/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml @@ -0,0 +1,13 @@ +id: stark.test_block +label: '' +uuid: 6dcd7278-40c5-426a-9804-4fd859748a30 +region: '-1' +weight: '' +cache: '1' +module: block_test +theme: stark +status: '1' +visibility: { } +plugin: test_html_id +configuration: + subject: 'Test block html id' diff --git a/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php index aeb7709..5f7b980 100644 --- a/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php +++ b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a block to test caching. @@ -36,7 +37,7 @@ public function blockSettings() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( '#children' => state()->get('block_test.content'), ); diff --git a/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php b/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php index c1823e1..1f43782 100644 --- a/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php +++ b/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Book navigation' block. @@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $current_bid = 0; if ($node = menu_get_object()) { $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php index d5c3d7b..77114fe 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Recent comments' block. @@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( '#theme' => 'comment_block', '#number' => $this->configuration['block_count'], diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php index afa7117..7ac7010 100644 --- a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php +++ b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides an 'Active forum topics' block. @@ -24,7 +25,7 @@ class ActiveTopicsBlock extends ForumBlockBase { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $query = db_select('forum_index', 'f') ->fields('f') ->addTag('node_access') diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php index 083469c..2cfcb8b 100644 --- a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php +++ b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'New forum topics' block. @@ -24,7 +25,7 @@ class NewTopicsBlock extends ForumBlockBase { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $query = db_select('forum_index', 'f') ->fields('f') ->addTag('node_access') diff --git a/core/modules/help/config/plugin.core.block.seven.help.yml b/core/modules/help/config/plugin.core.block.seven.help.yml deleted file mode 100644 index f75e2d7..0000000 --- a/core/modules/help/config/plugin.core.block.seven.help.yml +++ /dev/null @@ -1,20 +0,0 @@ -id: seven.help -label: '' -region: help -weight: '' -cache: '-1' -module: system -theme: seven -status: '1' -visibility: - path: - visibility: '0' - pages: '' - role: - roles: { } - node_type: - types: - article: '0' - page: '0' - visibility__active_tab: edit-visibility-path -plugin: system_help_block diff --git a/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php b/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php index a698695..89d6562 100644 --- a/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php +++ b/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Language switcher' block. @@ -33,7 +34,7 @@ function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $build = array(); $path = drupal_is_front_page() ? '' : current_path(); list($plugin_id, $type) = explode(':', $this->getPluginId()); diff --git a/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php index 7134dc50..2924bee 100644 --- a/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php +++ b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php @@ -10,6 +10,7 @@ use Drupal\system\Plugin\block\block\SystemMenuBlock; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a generic Menu block. @@ -26,7 +27,7 @@ class MenuBlock extends SystemMenuBlock { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { list($plugin, $menu) = explode(':', $this->getPluginId()); return menu_tree($menu); } diff --git a/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php b/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php index cb05c5c..d9abc2d 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php +++ b/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Recent content' block. @@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { if ($nodes = node_get_recent($this->configuration['block_count'])) { return array( '#theme' => 'node_recent_block', diff --git a/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php b/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php index 5c83e27..b83d9f4 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php +++ b/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Syndicate' block that links to the site's RSS feed. @@ -41,7 +42,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( '#theme' => 'feed_icon', '#url' => 'rss.xml', diff --git a/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php b/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php index b597741..5b96e3b 100644 --- a/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php +++ b/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Most recent poll' block. @@ -67,7 +68,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $poll = node_load($this->record); if ($poll->nid) { $poll = poll_block_latest_poll_view($poll); diff --git a/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php b/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php index d9bdb7c..4cdc83f 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php +++ b/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Search form' block. @@ -32,7 +33,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array(drupal_get_form('search_block_form')); } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php index d236a19..818650b 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Shortcut' block. @@ -25,7 +26,7 @@ class ShortcutsBlock extends BlockBase { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( shortcut_renderable_links(shortcut_current_displayed_set()), ); diff --git a/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php b/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php index 8c9fdf6..3fc4099 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php +++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Popular content' block. @@ -118,7 +119,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $content = array(); if ($this->day_list) { diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php index 6026f83..9b8d75c 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'System Help' block. @@ -40,7 +41,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( '#children' => $this->help, ); diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php index 8b40092..0c8a708 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Main page content' block. @@ -25,7 +26,7 @@ class SystemMainBlock extends BlockBase { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( drupal_set_page_content() ); diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php index 0307257..6087fa7 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'System Menu' block. @@ -35,7 +36,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { list($plugin, $derivative) = explode(':', $this->getPluginId()); // Derivatives are prefixed with 'menu-'. $menu = substr($derivative, 5); diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php index b363725..7fe9d29 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Powered by Drupal' block. @@ -25,7 +26,7 @@ class SystemPoweredByBlock extends BlockBase { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { return array( '#children' => theme('system_powered_by'), ); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index db722bb..22e6cb9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -29,7 +29,7 @@ class EntityCrudHookTest extends WebTestBase { * * @var array */ - public static $modules = array('entity_crud_hook_test', 'taxonomy', 'comment', 'file', 'entity_test'); + public static $modules = array('entity_crud_hook_test', 'taxonomy', 'block_test', 'block', 'comment', 'file', 'entity_test'); protected $ids = array(); @@ -67,6 +67,54 @@ protected function assertHookMessageOrder($messages) { } /** + * Tests hook invocations for CRUD operations on blocks. + */ + public function testBlockHooks() { + $entity = entity_create('block', array( + 'id' => 'stark.test_block', + 'plugin' => 'test_html_id', + )); + $_SESSION['entity_crud_hook_test'] = array(); + $entity->save(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_presave called', + 'entity_crud_hook_test_entity_presave called for type block', + 'entity_crud_hook_test_block_insert called', + 'entity_crud_hook_test_entity_insert called for type block', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity = entity_load('block', $entity->id()); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_entity_load called for type block', + 'entity_crud_hook_test_block_load called', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity->label = 'New label'; + $entity->save(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_presave called', + 'entity_crud_hook_test_entity_presave called for type block', + 'entity_crud_hook_test_block_update called', + 'entity_crud_hook_test_entity_update called for type block', + )); + + $_SESSION['entity_crud_hook_test'] = array(); + $entity->delete(); + + $this->assertHookMessageOrder(array( + 'entity_crud_hook_test_block_predelete called', + 'entity_crud_hook_test_entity_predelete called for type block', + 'entity_crud_hook_test_block_delete called', + 'entity_crud_hook_test_entity_delete called for type block', + )); + } + + /** * Tests hook invocations for CRUD operations on comments. */ public function testCommentHooks() { diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index 8a1e43c..f2bb297 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -15,6 +15,13 @@ function entity_crud_hook_test_entity_presave(EntityInterface $entity) { } /** + * Implements hook_block_presave(). + */ +function entity_crud_hook_test_block_presave() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_presave(). */ function entity_crud_hook_test_comment_presave() { @@ -64,6 +71,13 @@ function entity_crud_hook_test_entity_insert(EntityInterface $entity) { } /** + * Implements hook_block_insert(). + */ +function entity_crud_hook_test_block_insert() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_insert(). */ function entity_crud_hook_test_comment_insert() { @@ -113,6 +127,13 @@ function entity_crud_hook_test_entity_load(array $entities, $type) { } /** + * Implements hook_block_load(). + */ +function entity_crud_hook_test_block_load() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_load(). */ function entity_crud_hook_test_comment_load() { @@ -162,6 +183,13 @@ function entity_crud_hook_test_entity_update(EntityInterface $entity) { } /** + * Implements hook_block_update(). + */ +function entity_crud_hook_test_block_update() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_update(). */ function entity_crud_hook_test_comment_update() { @@ -211,6 +239,13 @@ function entity_crud_hook_test_entity_predelete(EntityInterface $entity) { } /** + * Implements hook_block_predelete(). + */ +function entity_crud_hook_test_block_predelete() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_predelete(). */ function entity_crud_hook_test_comment_predelete() { @@ -260,6 +295,13 @@ function entity_crud_hook_test_entity_delete(EntityInterface $entity) { } /** + * Implements hook_block_delete(). + */ +function entity_crud_hook_test_block_delete() { + $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); +} + +/** * Implements hook_comment_delete(). */ function entity_crud_hook_test_comment_delete() { diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php index 51bc8ee..996e15d 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'User login' block. @@ -32,7 +33,7 @@ public function blockAccess() { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $form = drupal_get_form('user_login_form'); unset($form['name']['#attributes']['autofocus']); unset($form['name']['#description']); diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php index 7f97df6..2ea4b89 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a "Who's new" block. @@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { // Retrieve a list of new users who have accessed the site successfully. $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])->fetchAll(); $build = array( diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php index 75f23f0..aee6ce1 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a "Who's online" block. @@ -78,7 +79,7 @@ public function blockSubmit($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { // Count users active within the defined period. $interval = REQUEST_TIME - $this->configuration['seconds_online']; 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 6d74ee4..7939f5c 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 @@ -11,6 +11,7 @@ use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a generic Views block. @@ -71,10 +72,10 @@ public function blockForm($form, &$form_state) { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $block) { $output = $this->view->executeDisplay($this->displayID); - // Set the subject to the title configured in the view. - $this->configuration['label'] = filter_xss_admin($this->view->getTitle()); + // Set the label to the title configured in the view. + $block->set('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); diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php index 2d51c25..40baebb 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\block\Plugin\Core\Entity\Block; /** * Provides a 'Views Exposed Filter' block. @@ -25,7 +26,7 @@ class ViewsExposedFilterBlock extends ViewsBlock { /** * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function blockBuild() { + public function blockBuild(Block $entity) { $type = 'exp'; $output = $this->view->display_handler->viewSpecialBlocks($type); // Before returning the block output, convert it to a renderable array with diff --git a/core/profiles/standard/config/plugin.core.block.seven.help.yml b/core/profiles/standard/config/plugin.core.block.seven.help.yml index 5b3ad82..bf2be94 100644 --- a/core/profiles/standard/config/plugin.core.block.seven.help.yml +++ b/core/profiles/standard/config/plugin.core.block.seven.help.yml @@ -1,4 +1,4 @@ -id: bartik.content +id: seven.help plugin: system_help_block theme: seven status: '1'