diff -u b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php --- b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php +++ b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php @@ -7,11 +7,30 @@ namespace Drupal\Core\Plugin\Factory; use Drupal\Component\Plugin\Factory\DefaultFactory; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin factory to use a factory method. */ -class MethodFactory extends DefaultFactory { +class MethodFactory extends DefaultFactory implements ContainerAwareInterface { + + /** + * The injection container for this object. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Injects the service container used by this object. + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The service container this object should use. + */ + public function setContainer(ContainerInterface $container = NULL) { + $this->container = $container; + } /** * Overrides \Drupal\Component\Plugin\Factory\DefaultFactory::createInstance(). @@ -19,7 +38,7 @@ public function createInstance($plugin_id, array $configuration) { $plugin_definition = $this->discovery->getDefinition($plugin_id); $plugin_class = static::getPluginClass($plugin_id, $plugin_definition); - return $plugin_class::create(drupal_container(), $configuration, $plugin_id, $plugin_definition); + return $plugin_class::create($this->container, $configuration, $plugin_id, $plugin_definition); } } diff -u b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php --- b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php @@ -7,19 +7,19 @@ namespace Drupal\views\Plugin; -use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Component\Plugin\ContainerAwarePluginManagerBase; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; -use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Factory\MethodFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin type manager for all views plugins. */ -class ViewsPluginManager extends PluginManagerBase { +class ViewsPluginManager extends ContainerAwarePluginManagerBase { /** * Constructs a ViewsPluginManager object. @@ -48,2 +48,11 @@ + /** + * Overrides \Drupal\Component\Plugin\ContainerAwarePluginManagerBase::setContainer() + */ + public function setContainer(ContainerInterface $container = NULL) { + parent::setContainer($container); + + $this->factory->setContainer($this->container); + } + } only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/ContainerAwarePluginManagerBase.php @@ -0,0 +1,34 @@ +container = $container; + } + +} only in patch2: unchanged: --- a/core/modules/views/lib/Drupal/views/ViewsBundle.php +++ b/core/modules/views/lib/Drupal/views/ViewsBundle.php @@ -25,7 +25,8 @@ public function build(ContainerBuilder $container) { foreach (ViewExecutable::getPluginTypes() as $type) { $container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\ViewsPluginManager') ->addArgument($type) - ->addArgument('%container.namespaces%'); + ->addArgument('%container.namespaces%') + ->addMethodCall('setContainer', array(new Reference('service_container'))); } $container->register('views.views_data', 'Drupal\views\ViewsDataCache')