Commit 541dd42e authored by tim.plunkett's avatar tim.plunkett Committed by tim.plunkett

Issue #1727266 by tim.plunkett, aspilicious, damiankloip: Lazy load plugin...

Issue #1727266 by tim.plunkett, aspilicious, damiankloip: Lazy load plugin managers with dependency injection.
parent 0e5f711e
......@@ -51,6 +51,36 @@ public function __construct(array $configuration, $plugin_id, DiscoveryInterface
$this->construct();
}
/**
* Returns the valid types of plugins that can be used.
*
* @return array
* An array of plugin type strings.
*/
public static function getTypes() {
return array(
'access',
'area',
'argument',
'argument_default',
'argument_validator',
'cache',
'display_extender',
'display',
'exposed_form',
'field',
'filter',
'join',
'pager',
'query',
'relationship',
'row',
'sort',
'style',
'wizard',
);
}
/**
* Information about options for all kinds of purposes will be held here.
* @code
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Tests;
use ReflectionClass;
use Drupal\views\Plugin\Type\ViewsPluginManager;
/**
* Checks general plugin data and instances for all plugin types.
......@@ -88,9 +87,10 @@ public function testPluginData() {
* This will iterate through all plugins from _views_fetch_plugin_data().
*/
public function testPluginInstances() {
$container = drupal_container();
foreach ($this->definitions as $type => $plugins) {
// Get a plugin manager for this type.
$manager = new ViewsPluginManager($type);
$manager = $container->get("plugin.manager.views.$type");
foreach ($plugins as $definition) {
// Get a reflection class for this plugin.
// We only want to test true plugins, i.e. They extend PluginBase.
......
<?php
/**
* @file
* Definition of Drupal\views\ViewsBundle.
*/
namespace Drupal\views;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Drupal\views\Plugin\views\PluginBase;
/**
* Views dependency injection container.
*/
class ViewsBundle extends Bundle {
/**
* Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build().
*/
public function build(ContainerBuilder $container) {
foreach (PluginBase::getTypes() as $type) {
$container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\Type\ViewsPluginManager')
->addArgument($type);
}
}
}
......@@ -12,7 +12,7 @@
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\views\TempStore\UserTempStore;
use Drupal\views\View;
use Drupal\views\Plugin\Type\ViewsPluginManager;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\Component\Plugin\Exception\PluginException;
/**
......@@ -1324,7 +1324,7 @@ function views_get_handler($table, $field, $type, $override = NULL) {
}
// @todo This is crazy. Find a way to remove the override functionality.
$manager = new ViewsPluginManager($type);
$manager = drupal_container()->get("plugin.manager.views.$type");
$plugin_id = !empty($definition['override handler']) ? $definition['override handler'] : $definition['id'];
// Try to use the overridden handler.
try {
......@@ -1412,8 +1412,7 @@ function views_fetch_plugin_names($type, $key = NULL, $base = array()) {
* The created plugin instance.
*/
function views_get_plugin($type, $plugin_id) {
$manager = new ViewsPluginManager($type);
return $manager->createInstance($plugin_id);
return drupal_container()->get("plugin.manager.views.$type")->createInstance($plugin_id);
}
/**
......@@ -1428,10 +1427,10 @@ function views_get_plugin($type, $plugin_id) {
*/
function views_get_plugin_definitions($type = FALSE) {
$plugins = array();
$plugin_types = $type ? array($type) : array('access', 'area', 'argument', 'argument_default', 'argument_validator', 'cache', 'display_extender', 'display', 'exposed_form', 'field', 'filter', 'join', 'pager', 'query', 'relationship', 'row', 'sort', 'style', 'wizard');
$plugin_types = $type ? array($type) : PluginBase::getTypes();
$container = drupal_container();
foreach ($plugin_types as $plugin_type) {
$manager = new ViewsPluginManager($plugin_type);
$plugins[$plugin_type] = $manager->getDefinitions();
$plugins[$plugin_type] = $container->get("plugin.manager.views.$plugin_type")->getDefinitions();
}
if ($type) {
return $plugins[$type];
......@@ -1451,8 +1450,7 @@ function views_get_plugin_definitions($type = FALSE) {
* A plugin definition.
*/
function views_get_plugin_definition($type, $plugin_id) {
$manager = new ViewsPluginManager($type);
return $manager->getDefinition($plugin_id);
return drupal_container()->get("plugin.manager.views.$type")->getDefinition($plugin_id);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment