diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index a298fe1..8a1cce3 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Plugin; use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; -use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; +use Drupal\Core\Plugin\Discovery\DerivativeDiscoveryDecorator; use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Utility\NestedArray; @@ -98,7 +98,7 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt public function __construct($subdir, \Traversable $namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->subdir = $subdir; $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $annotation_namespaces, $plugin_definition_annotation_name); - $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); + $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); } diff --git a/core/lib/Drupal/Core/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/DerivativeDiscoveryDecorator.php index 400af19..5483c6e 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/DerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/DerivativeDiscoveryDecorator.php @@ -7,9 +7,9 @@ namespace Drupal\Core\Plugin\Discovery; -use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator as ComponentDerivativeDiscoveryDecorator; -class DerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator { +class DerivativeDiscoveryDecorator extends ComponentDerivativeDiscoveryDecorator { /** * {@inheritdoc} @@ -18,14 +18,13 @@ protected function getDerivativeFetcher($base_plugin_id, array $base_definition) if (!isset($this->derivativeFetchers[$base_plugin_id])) { $this->derivativeFetchers[$base_plugin_id] = FALSE; if (isset($base_definition['derivative'])) { - $class = $base_definition['derivative']; - // If the derivative class provides a factory method, pass the container - // to it. - if (is_subclass_of($class, 'Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface')) { - $this->derivativeFetchers[$base_plugin_id] = $class::create(\Drupal::getContainer(), $base_plugin_id); + $derivative = $base_definition['derivative']; + if (class_exists($derivative)) { + $this->derivativeFetchers[$base_plugin_id] = new $derivative($base_plugin_id); } + // Assume a service name has been provided. else { - $this->derivativeFetchers[$base_plugin_id] = new $class($base_plugin_id); + $this->derivativeFetchers[$base_plugin_id] = \Drupal::service($derivative); } } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php index 270ed26..fc86d2b 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php @@ -20,7 +20,7 @@ * id = "views_block", * admin_label = @Translation("Views Block"), * module = "views", - * derivative = "Drupal\views\Plugin\Derivative\ViewsBlock" + * derivative = "plugin.derivative.views.block" * ) */ class ViewsBlock extends BlockBase { diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php index 31dbf12..be0d196 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php @@ -7,16 +7,15 @@ namespace Drupal\views\Plugin\Derivative; -use Drupal\Core\Entity\EntityStorageControllerInterface; -use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Entity\EntityManager; +use Drupal\Component\Plugin\Derivative\DerivativeInterface; /** * Provides block plugin definitions for all Views block displays. * * @see \Drupal\views\Plugin\block\block\ViewsBlock */ -class ViewsBlock implements ContainerDerivativeInterface { +class ViewsBlock implements DerivativeInterface { /** * List of derivative definitions. @@ -26,13 +25,6 @@ class ViewsBlock implements ContainerDerivativeInterface { protected $derivatives = array(); /** - * The base plugin ID. - * - * @var string - */ - protected $base_plugin_id; - - /** * The view storage controller. * * @var \Drupal\Core\Entity\EntityStorageControllerInterface @@ -40,16 +32,6 @@ class ViewsBlock implements ContainerDerivativeInterface { protected $viewStorageController; /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, $base_plugin_id) { - return new static( - $base_plugin_id, - $container->get('plugin.manager.entity')->getStorageController('view') - ); - } - - /** * Constructs a ViewsBlock object. * * @param string $base_plugin_id @@ -57,9 +39,8 @@ public static function create(ContainerInterface $container, $base_plugin_id) { * @param \Drupal\Core\Entity\EntityStorageControllerInterface $view_storage_controller * The entity storage controller to load views. */ - public function __construct($base_plugin_id, EntityStorageControllerInterface $view_storage_controller) { - $this->basePluginId = $base_plugin_id; - $this->viewStorageController = $view_storage_controller; + public function __construct(EntityManager $entity_manager) { + $this->viewStorageController = $entity_manager->getStorageController('view'); } /** diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index d5ab9d9..23695ee 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -56,6 +56,9 @@ services: plugin.manager.views.wizard: class: Drupal\views\Plugin\ViewsPluginManager arguments: [wizard, '@container.namespaces'] + plugin.derivative.views.block: + class: Drupal\views\Plugin\Derivative\ViewsBlock + arguments: ['@plugin.manager.entity'] views.views_data: class: Drupal\views\ViewsData arguments: ['@cache.views_info', '@config.factory', '@module_handler', '@language_manager']