diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 9c90a5a..0a7cf86 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; } } 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 84e43e7..725d916 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_container()->get('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,42 @@ 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(); */ - public function getExportProperties() { - $names = array( + public function set($property_name, $value) { + if (!in_array($property_name, $this->exportProperties()) && $property_name != 'settings') { + $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)) { + $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 { + $this->getPlugin()->setConfig($property_name, $value); + parent::set($property_name, $value); + } + } + + protected function exportProperties() { + return array( 'id', 'label', 'uuid', @@ -178,8 +222,14 @@ public function getExportProperties() { 'plugin', 'settings', ); + } + + /** + * 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; 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/node/node.module b/core/modules/node/node.module index 8019ff3..a668c61 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2029,7 +2029,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/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/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php index 4dbb64d..53beee4 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); @@ -77,7 +77,7 @@ public function form($form, &$form_state) { public function build() { $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);