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 10bc52e..e288f27 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 @@ -62,9 +62,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 afcef0e..f522b8f 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 @@ -62,9 +62,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { // 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/block.module b/core/modules/block/block.module index 18b9d27..febb1bf 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -326,8 +326,10 @@ function _block_get_renderable_region($list = array()) { else { $key_components = explode('.', $key); $id = array_pop($key_components); + // @todo http://drupal.org/node/1942286 $build[$key] = array( - '#block' => $block, + '#entity' => $block, + '#block' => (object) $block->getPlugin()->getConfig(), '#weight' => $block->get('weight'), '#theme_wrappers' => array('block'), '#pre_render' => array('_block_get_renderable_block'), @@ -488,11 +490,12 @@ function block_load($entity_id) { * A renderable array. */ function _block_get_renderable_block($element) { - $block = $element['#block']; + $block = $element['#entity']; // Don't bother to build blocks that aren't accessible. if ($element['#access'] = $block->access()) { $element += entity_view($block, 'block'); } + unset($element['#entity']); return $element; } @@ -534,7 +537,8 @@ function block_rebuild() { function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); - $variables['block'] = (object) $variables['elements']['#block_config']; + // @todo http://drupal.org/node/1942286 + $variables['block'] = (object) $variables['elements']['#block']; // All blocks get an independent counter for each region. if (!isset($block_counter[$variables['block']->region])) { @@ -565,13 +569,13 @@ function template_preprocess_block(&$variables) { // We can safely explode on : because we know the Block plugin type manager // enforces that delimiter for all derivatives. - $parts = explode(':', $variables['elements']['#block']->get('plugin')); + $parts = explode(':', $variables['elements']['#block']->plugin); $suggestion = 'block'; while ($part = array_shift($parts)) { $variables['theme_hook_suggestions'][] = $suggestion .= '__' . strtr($part, '-', '_'); } // Create a valid HTML ID and make sure it is unique. - if ($id = $variables['elements']['#block']->id()) { + if ($id = $variables['elements']['#block']->id) { $config_id = explode('.', $id); $machine_name = array_pop($config_id); $variables['block_html_id'] = drupal_html_id('block-' . $machine_name); diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index a3ce18c..ec678d8 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -8,7 +8,7 @@ use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType; use Drupal\custom_block\Plugin\Core\Entity\CustomBlock; use Drupal\custom_block\Plugin\block\block\CustomBlockBlock; -use Drupal\block\Plugin\Core\Entity\Block; +use Drupal\block\BlockInterface; /** * Implements hook_menu_local_tasks(). @@ -292,9 +292,9 @@ function custom_block_admin_paths() { /** * Implements hook_block_view_alter(). */ -function custom_block_block_view_alter(array &$build, Block $block) { +function custom_block_block_view_alter(array &$build, BlockInterface $block) { // Add contextual links for custom blocks. - if ($block->getPlugin() instanceof CustomBlockBlock) { + if ($block instanceof CustomBlockBlock) { // Move contextual links from inner content to outer wrapper. $build['#contextual_links']['custom_block'] = $build['content']['#contextual_links']['custom_block']; unset($build['content']['#contextual_links']['custom_block']); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php index 9219264..c0d0e4b 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlockBlock.php @@ -73,9 +73,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { // @todo Clean up when http://drupal.org/node/1874498 lands. list(, $uuid) = explode(':', $this->getPluginId()); if ($block = entity_load_by_uuid('custom_block', $uuid)) { diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 9c90a5a..9f83308 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\PluginBase; use Drupal\block\Plugin\Core\Entity\Block; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Defines a base block implementation that most blocks plugins will extend. @@ -21,22 +20,6 @@ abstract class BlockBase extends PluginBase implements BlockInterface { /** - * The entity using this plugin. - * - * @var \Drupal\block\Plugin\Core\Entity\Block - */ - protected $entity; - - /** - * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). - */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery, Block $entity) { - parent::__construct($configuration, $plugin_id, $discovery); - - $this->entity = $entity; - } - - /** * Returns plugin-specific settings for the block. * * Block plugins only need to override this method if they override the @@ -142,7 +125,7 @@ public function access() { global $user; // Deny access to disabled blocks. - if (!$this->entity->get('status')) { + if (!$this->configuration['status']) { return FALSE; } @@ -150,7 +133,7 @@ public function access() { // If a block has no roles associated, it is displayed for every role. // For blocks with roles associated, if none of the user's roles matches // the settings from this block, access is denied. - $visibility = $this->entity->get('visibility'); + $visibility = $this->configuration['visibility']; if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), array_keys($user->roles))) { // No match. return FALSE; @@ -202,7 +185,7 @@ public function access() { // Check other modules for block access rules. foreach (module_implements('block_access') as $module) { - if (module_invoke($module, 'block_access', $this->entity) === FALSE) { + if (module_invoke($module, 'block_access', $this) === FALSE) { return FALSE; } } @@ -489,4 +472,40 @@ public function submit($form, &$form_state) { */ public function blockSubmit($form, &$form_state) {} + /** + * Implements \Drupal\block\BlockInterface::build(). + */ + public function build() { + $build = array(); + $content = array(); + if ($content = $this->blockBuild()) { + // @todo http://drupal.org/node/1942286 + $build = array( + '#block' => (object) $this->getConfig(), + '#theme_wrappers' => array('block'), + ); + // The label is the only string we actually render, so we need to handle + // it specially. + // @todo: Give the implications of this line further thought in + // http://drupal.org/node/1941244. + $build['#block']->label = check_plain($this->configuration['label']); + } + $build['content'] = $content; + + // All blocks, even when empty, should be available for altering. + $id = str_replace(':', '__', $this->configuration['plugin']); + drupal_alter(array('block_view', "block_view_$id"), $build, $this); + return $build; + } + + /** + * Builds the renderable array of the block's content. + * + * @return array + * A renderable array representing the content of the block. + * + * @see \Drupal\block\BlockRenderController + */ + abstract protected function blockBuild(); + } diff --git a/core/modules/block/lib/Drupal/block/BlockInterface.php b/core/modules/block/lib/Drupal/block/BlockInterface.php index 65bdee3..137c878 100644 --- a/core/modules/block/lib/Drupal/block/BlockInterface.php +++ b/core/modules/block/lib/Drupal/block/BlockInterface.php @@ -96,7 +96,7 @@ public function submit($form, &$form_state); * Builds and returns the renderable array for this block plugin. * * @return array - * A renderable array representing the content of the block. + * A renderable array for wrapping the content of the block. * * @see \Drupal\block\BlockRenderController */ diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php index e1c560e..5d3eefa 100644 --- a/core/modules/block/lib/Drupal/block/BlockRenderController.php +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -23,42 +23,6 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang } /** - * Provides entity-specific defaults to the build process. - * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity for which the defaults should be provided. - * @param string $view_mode - * The view mode that should be used. - * @param string $langcode - * (optional) For which language the entity should be prepared, defaults to - * the current content language. - * - * @return array - * An array of defaults to add into the entity render array. - */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { - // @todo \Drupal\block\Tests\BlockTest::testCustomBlock() assuemes that a - // block can be rendered without any of its wrappers. To do so, it uses a - // custom view mode, and we choose to only add the wrappers on the default - // view mode, 'block'. - if ($view_mode != 'block') { - return array(); - } - - return array( - '#block' => $entity, - '#weight' => $entity->get('weight'), - '#theme_wrappers' => array('block'), - '#block_config' => array( - 'id' => $entity->get('plugin'), - 'region' => $entity->get('region'), - 'module' => $entity->get('module'), - 'label' => check_plain($entity->label()), - ), - ); - } - - /** * Implements Drupal\Core\Entity\EntityRenderControllerInterface::view(). */ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { @@ -73,15 +37,13 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $build = array(); foreach ($entities as $entity_id => $entity) { // Allow blocks to be empty, do not add in the defaults. - if ($content = $entity->getPlugin()->build()) { - $build[$entity_id] = $this->getBuildDefaults($entity, $view_mode, $langcode); - } - $build[$entity_id]['content'] = $content; + $build[$entity_id] = $entity->getPlugin()->build(); + $build[$entity_id]['#weight'] = $entity->get('weight'); - // All blocks, even when empty, should be available for altering. - $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); + // Separate the theme and machine name components from the entity id. + list(, $name) = explode('.', $entity->id()); + $plugin = $entity->getPlugin(); + drupal_alter(array("block_view_$name"), $build[$entity_id], $plugin); } 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 75d82e8..009c1a6 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 @@ -123,8 +123,16 @@ public function getPlugin() { // Create a plugin instance and store its configuration as settings. try { - $this->instance = drupal_container()->get('plugin.manager.block')->createInstance($this->plugin, $this->settings, $this); - $this->settings += $this->instance->getConfig(); + $properties = $this->getExportProperties(); + unset($properties['settings']); + $this->instance = \Drupal::service('plugin.manager.block')->createInstance($this->plugin); + $this->instance->getConfig(); + foreach ($properties as $key => $value) { + $this->instance->setConfig($key, $value); + } + foreach ($this->settings as $key => $value) { + $this->instance->setConfig($key, $value); + } } catch (PluginException $e) { // Ignore blocks belonging to disabled modules, but re-throw valid @@ -138,6 +146,14 @@ public function getPlugin() { } /** + * Overrides \Drupal\Core\Entity\EntityInterface::label(). + */ + public function label($langcode = NULL) { + $configuration = $this->getPlugin()->getConfig(); + return $configuration['label']; + } + + /** * Overrides \Drupal\Core\Entity\Entity::uri(); */ public function uri() { @@ -159,14 +175,73 @@ public function get($property_name, $langcode = NULL) { if ($property_name == 'theme' && !$value) { list($value) = explode('.', $this->id()); } + elseif (!in_array($property_name, $this->exportProperties())) { + // Support geting plugin-specific settings with the get() method. + $settings = parent::get('settings'); + if (isset($settings[$property_name])) { + $value = $settings[$property_name]; + } + } return $value; } /** - * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::set(); + * + * The plugin configuration is the canonical source for any configuration + * within the plugin. The plugin does not care about the storage mechanism, + * so the entity must maintain both its own properties as well as the + * configuration of the plugin. + * + * Any property that exists in Block::exportProperties() can be handled by + * the parent method, with the exception of the settings property. Any property + * that is not documented in Block::exportProperties() is to be considered an + * internal configuration property of the plugin and should be maintained on + * the entity within the settings property. Setting of the settings property + * directly is supported, but all set() calls to the settings property are + * additive and will not remove settings values. + * + * @todo The basic functionality of this cannot change. The plugin + * configuration and entity values must always be up to date, but we should + * revisit whether this can be simplified. http://drupal.org/node/1942262 */ - public function getExportProperties() { - $names = array( + public function set($property_name, $value) { + if (!in_array($property_name, $this->exportProperties()) && $property_name != 'settings') { + // If the property is not a property of the entity, assume it belongs in + // the settings property of the entity, and set the plugin configuration + // value appropriately. + $settings = $this->get('settings'); + $settings[$property_name] = $value; + $this->getPlugin()->setConfig($property_name, $value); + parent::set('settings', $settings); + } + elseif ($property_name == 'settings' && is_array($value)) { + // If we are updating the settings property and the value passed was an + // array, add each of the key value pairs to the plugin configuration and + // set the entity's 'settings' property. + $settings = $this->get('settings'); + foreach ($value as $key => $key_value) { + $this->getPlugin()->setConfig($key, $key_value); + $settings[$key] = $key_value; + } + parent::set('settings', $settings); + } + else { + // If we're updating a property of the entity, just add the value to the + // plugin configuration as well. + $this->getPlugin()->setConfig($property_name, $value); + parent::set($property_name, $value); + } + } + + /** + * Returns a list of properties to export for this entity. + * + * @return array + * A simple array of property names on this entity. + */ + protected function exportProperties() { + return array( 'id', 'label', 'uuid', @@ -179,11 +254,27 @@ public function getExportProperties() { 'settings', 'langcode', ); + } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties(); + */ + public function getExportProperties() { $properties = array(); - foreach ($names as $name) { + foreach ($this->exportProperties() as $name) { $properties[$name] = $this->get($name); } return $properties; } + /** + * Implements \Drupal\Core\Entity\EntityInterface::save(). + */ + public function save() { + // Get any key value pairs in the plugin configuration that are not in the + // entity's properties and add them to the entity's settings property. + $this->settings = array_diff_key($this->getPlugin()->getConfig(), $this->getExportProperties()); + return parent::save(); + } + } diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index d5dedb9..228f3db 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -35,14 +35,7 @@ public function __construct(array $namespaces) { $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'block'); $this->discovery = new CacheDecorator($this->discovery, 'block_plugins:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache_block', CacheBackendInterface::CACHE_PERMANENT, array('block')); - } - - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance(). - */ - public function createInstance($plugin_id, array $configuration = array(), Block $entity = NULL) { - $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this->discovery); - return new $plugin_class($configuration, $plugin_id, $this->discovery, $entity); + $this->factory = new DefaultFactory($this); } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php index d707c80..10ad233 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php @@ -44,12 +44,8 @@ function testBlockThemeHookSuggestions() { )); $variables = array(); - $variables['elements']['#block'] = $block; - $variables['elements']['#block_config'] = $block->getPlugin()->getConfig() + array( - 'id' => $block->get('plugin'), - 'region' => $block->get('region'), - 'module' => $block->get('module'), - ); + // @todo http://drupal.org/node/1942286 + $variables['elements']['#block'] = (object) $block->getPlugin()->getConfig(); $variables['elements']['#children'] = ''; // Test adding a class to the block content. $variables['content_attributes']['class'][] = 'test-class'; 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 dd7a423..6484840 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 @@ -34,9 +34,9 @@ public function settings() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 165c798..9f44c72 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 @@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 bd7b49b..ea804a8 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 @@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 e3ff7dd..a5611d3 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 @@ -22,9 +22,9 @@ class ActiveTopicsBlock extends ForumBlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 71d4c3b..7b70836 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 @@ -22,9 +22,9 @@ class NewTopicsBlock extends ForumBlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $query = db_select('forum_index', 'f') ->fields('f') ->addTag('node_access') 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 53c58e7..9e9caee 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 @@ -31,9 +31,9 @@ function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 c535fc6..72a0474 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 @@ -24,9 +24,9 @@ class MenuBlock extends SystemMenuBlock { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { list($plugin, $menu) = explode(':', $this->getPluginId()); return menu_tree($menu); } diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index a4a6718..055f2be 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -12,7 +12,7 @@ */ use Drupal\Core\Entity\EntityInterface; -use Drupal\block\Plugin\Core\Entity\Block; +use Drupal\block\BlockInterface; use Drupal\system\Plugin\Core\Entity\Menu; use Drupal\system\Plugin\block\block\SystemMenuBlock; use Symfony\Component\HttpFoundation\JsonResponse; @@ -412,9 +412,9 @@ function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, /** * Implements hook_block_view_alter(). */ -function menu_block_view_alter(array &$build, Block $block) { +function menu_block_view_alter(array &$build, BlockInterface $block) { // Add contextual links for system menu blocks. - if ($block->getPlugin() instanceof SystemMenuBlock) { + if ($block instanceof SystemMenuBlock) { foreach (element_children($build['content']) as $key) { $build['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($build['content'][$key]['#original_link']['menu_name'])); } 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 083a096..befae9a 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 @@ -59,9 +59,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 af627a2..246eff2 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 @@ -39,9 +39,9 @@ public function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { return array( '#theme' => 'feed_icon', '#url' => 'rss.xml', diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 6ce0874..f4d5e6b 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2027,7 +2027,8 @@ function node_form_block_form_alter(&$form, &$form_state) { * if the visibility conditions are not met. */ function node_block_access($block) { - $visibility = $block->get('visibility'); + $configuration = $block->getConfig(); + $visibility = $configuration['visibility']; if (!empty($visibility)) { $allowed_types = array(); $node = menu_get_object(); diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 6d31124..1eb27e9 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -5,6 +5,8 @@ * Implement OpenID Relying Party support for Drupal */ +use Drupal\block\BlockInterface; + /** * Implements hook_menu(). */ @@ -158,13 +160,13 @@ function openid_user_logout($account) { } /** - * Implements hook_block_view_MODULE_DELTA_alter(). + * Implements hook_block_view_ID_alter(). * * Adds the OpenID login form to the user login block. * * @see \Drupal\user\Plugin\block\block\UserLoginBlock */ -function openid_block_view_user_login_block_alter(&$build, $block) { +function openid_block_view_user_login_block_alter(&$build, BlockInterface $block) { // Only alter the block when it is non-empty, i.e. when no user is logged in. if (!isset($build['content']['user_login_form'])) { return; diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index cc29255..3ff93fe 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -486,7 +486,8 @@ function overlay_block_access($block) { // reason for duplicating effort here is performance; we do not even want // these blocks to be built if they are not going to be displayed. if ($regions_to_render = overlay_get_regions_to_render()) { - if (!in_array($block->get('region'), $regions_to_render)) { + $configuration = $block->getConfig(); + if (!in_array($configuration['region'], $regions_to_render)) { return FALSE; } } 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 bb06d35..405d41e 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 @@ -30,9 +30,9 @@ public function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 f610717..937e16a 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 @@ -23,9 +23,9 @@ class ShortcutsBlock extends BlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 7417bd8..a2033f6 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 @@ -116,9 +116,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 a5476c3..9621363 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 @@ -38,9 +38,9 @@ public function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 80510b0..6b739ff 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 @@ -23,9 +23,9 @@ class SystemMainBlock extends BlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 721ae2e..c1fe3c9 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 @@ -33,9 +33,9 @@ public function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { 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 958edc0..68c062a 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 @@ -23,9 +23,9 @@ class SystemPoweredByBlock extends BlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { return array( '#children' => theme('system_powered_by'), ); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 2c51ae0..ef46866 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2645,7 +2645,7 @@ function system_preprocess_block(&$variables) { // System menu blocks should get the same class as menu module blocks. default: - if ($variables['elements']['#block']->getPlugin() instanceof SystemMenuBlock) { + if ($variables['elements']['#block']->plugin == 'system_main_block') { $variables['attributes_array']['role'] = 'navigation'; $variables['classes_array'][] = 'block-menu'; } 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 716a315..bd293f5 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 @@ -30,9 +30,9 @@ public function blockAccess() { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $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 5f88f7f..4ee0547 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 @@ -62,9 +62,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { // 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 d88568a..db3433c 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 @@ -76,9 +76,9 @@ public function blockSubmit($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { // 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 4dbb64d..57289d7 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 @@ -42,8 +42,8 @@ class ViewsBlock extends BlockBase { /** * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery, Block $entity) { - parent::__construct($configuration, $plugin_id, $discovery, $entity); + public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { + parent::__construct($configuration, $plugin_id, $discovery); list($plugin, $delta) = explode(':', $this->getPluginId()); list($name, $this->displayID) = explode('-', $delta, 2); @@ -72,12 +72,12 @@ public function form($form, &$form_state) { } /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $output = $this->view->executeDisplay($this->displayID); // Set the label to the title configured in the view. - $this->entity->set('label', 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. $this->addContextualLinks($output); 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 cb9d37c..b4fad38 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 @@ -23,9 +23,9 @@ class ViewsExposedFilterBlock extends ViewsBlock { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). */ - public function build() { + public function blockBuild() { $output = $this->view->display_handler->viewExposedFormBlocks(); // Before returning the block output, convert it to a renderable array with // contextual links.