diff --git a/core/lib/Drupal/Component/Plugin/ContainerAwarePluginManagerBase.php b/core/lib/Drupal/Component/Plugin/ContainerAwarePluginManagerBase.php new file mode 100644 index 0000000..b8a2536 --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/ContainerAwarePluginManagerBase.php @@ -0,0 +1,34 @@ +container = $container; + } + +} diff --git a/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php new file mode 100644 index 0000000..5fdd677 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/Factory/MethodFactory.php @@ -0,0 +1,44 @@ +container = $container; + } + + /** + * Overrides \Drupal\Component\Plugin\Factory\DefaultFactory::createInstance(). + */ + 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($this->container, $configuration, $plugin_id, $plugin_definition); + } + +} diff --git a/core/lib/Drupal/Core/Plugin/MethodFactoryPluginBase.php b/core/lib/Drupal/Core/Plugin/MethodFactoryPluginBase.php new file mode 100644 index 0000000..f4be011 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/MethodFactoryPluginBase.php @@ -0,0 +1,40 @@ +discovery = new AlterDecorator($this->discovery, 'views_plugins_' . $type); $this->discovery = new CacheDecorator($this->discovery, 'views:' . $type, 'views_info'); - $this->factory = new DefaultFactory($this->discovery); + $this->factory = new MethodFactory($this); $this->defaults += array( 'parent' => 'parent', @@ -45,4 +46,13 @@ public function __construct($type, array $namespaces = array()) { ); } + /** + * Overrides \Drupal\Component\Plugin\ContainerAwarePluginManagerBase::setContainer() + */ + public function setContainer(ContainerInterface $container = NULL) { + parent::setContainer($container); + + $this->factory->setContainer($this->container); + } + } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php index 82d14f9..2cae7ff 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php @@ -7,11 +7,11 @@ namespace Drupal\views\Plugin\views; +use Drupal\Core\Plugin\MethodFactoryPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; -use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; use Drupal\views\ViewExecutable; -abstract class PluginBase extends ComponentPluginBase { +abstract class PluginBase extends MethodFactoryPluginBase { /** * Options for this plugin will be held here. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php index 75623b8..4cad187 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php @@ -6,7 +6,7 @@ */ namespace Drupal\views\Plugin\views\join; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\MethodFactoryPluginBase; /** * @defgroup views_join_handlers Views join handlers @@ -49,7 +49,7 @@ * * Extensions of this class can be used to create more interesting joins. */ -class JoinPluginBase extends PluginBase { +class JoinPluginBase extends MethodFactoryPluginBase { /** * The table to join (right table). diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php index 8ab0337..aeb3717 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php @@ -7,10 +7,14 @@ namespace Drupal\views\Plugin\views\style; +use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\views\Plugin\views\wizard\WizardInterface; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; + /** * Style plugin to render each item as a row in a table. * @@ -59,6 +63,30 @@ class Table extends StylePluginBase { */ public $order; + /** + * Contains the current request object. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * Overrides \Drupal\Core\Plugin\MethodFactoryPluginBase::create(). + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('request')); + } + + /** + * Constructs a Table object. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Request $request) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->request = $request; + } + + protected function defineOptions() { $options = parent::defineOptions(); @@ -80,7 +108,7 @@ protected function defineOptions() { * @return bool */ function build_sort() { - $order = drupal_container()->get('request')->query->get('order'); + $order = $this->request->query->get('order'); if (!isset($order) && ($this->options['default'] == -1 || empty($this->view->field[$this->options['default']]))) { return TRUE; } @@ -98,7 +126,7 @@ function build_sort() { * Add our actual sort criteria */ function build_sort_post() { - $query = drupal_container()->get('request')->query; + $query = $this->request->query; $order = $query->get('order'); if (!isset($order)) { // check for a 'default' clicksort. If there isn't one, exit gracefully. diff --git a/core/modules/views/lib/Drupal/views/ViewsBundle.php b/core/modules/views/lib/Drupal/views/ViewsBundle.php index 649fd7d..b6042c2 100644 --- 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')