From fc29f3cc9cc76457b48844d917d867c348e0c0e7 Mon Sep 17 00:00:00 2001 From: aspilicious <aspilicious@172527.no-reply.drupal.org> Date: Wed, 26 Sep 2012 22:27:27 +0200 Subject: [PATCH] Issue #1794844 by aspilicious: One manager for each use case. --- lib/Drupal/views/Plugin/Type/JoinManager.php | 51 +++++++++++++++++++ ...ewsPluginManager.php => PluginManager.php} | 9 ++-- .../views/Plugin/Type/WizardManager.php | 51 +++++++++++++++++++ lib/Drupal/views/ViewsBundle.php | 12 ++++- 4 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 lib/Drupal/views/Plugin/Type/JoinManager.php rename lib/Drupal/views/Plugin/Type/{ViewsPluginManager.php => PluginManager.php} (88%) create mode 100644 lib/Drupal/views/Plugin/Type/WizardManager.php diff --git a/lib/Drupal/views/Plugin/Type/JoinManager.php b/lib/Drupal/views/Plugin/Type/JoinManager.php new file mode 100644 index 000000000000..0e4801fdbebb --- /dev/null +++ b/lib/Drupal/views/Plugin/Type/JoinManager.php @@ -0,0 +1,51 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Plugin\Type\JoinManager. + */ + +namespace Drupal\views\Plugin\Type; + +use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Component\Plugin\Factory\DefaultFactory; +use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; +use Drupal\Core\Plugin\Discovery\CacheDecorator; + +class JoinManager extends PluginManagerBase { + + /** + * A list of Drupal core modules. + * + * @var array + */ + protected $coreModules = array(); + + /** + * Constructs a JoinManager object. + */ + public function __construct() { + // @todo Remove this hack in http://drupal.org/node/1708404. + views_init(); + + $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', 'join'), 'views:join', 'views_info'); + $this->factory = new DefaultFactory($this); + + $this->coreModules = views_core_modules(); + } + + /** + * Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition(). + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + $module = isset($definition['module']) ? $definition['module'] : 'views'; + $module_dir = in_array($module, $this->coreModules) ? 'views' : $module; + + $definition += array( + 'module' => $module_dir, + ); + } + +} diff --git a/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php b/lib/Drupal/views/Plugin/Type/PluginManager.php similarity index 88% rename from lib/Drupal/views/Plugin/Type/ViewsPluginManager.php rename to lib/Drupal/views/Plugin/Type/PluginManager.php index 535ac61826f8..4c7ffd9e2379 100644 --- a/lib/Drupal/views/Plugin/Type/ViewsPluginManager.php +++ b/lib/Drupal/views/Plugin/Type/PluginManager.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\views\Plugin\Type\ViewsPluginManager. + * Definition of Drupal\views\Plugin\Type\PluginManager. */ namespace Drupal\views\Plugin\Type; @@ -12,7 +12,7 @@ use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; -class ViewsPluginManager extends PluginManagerBase { +class PluginManager extends PluginManagerBase { /** * A list of Drupal core modules. @@ -21,11 +21,14 @@ class ViewsPluginManager extends PluginManagerBase { */ protected $coreModules = array(); + /** + * Constructs a PluginManager object. + */ public function __construct($type) { // @todo Remove this hack in http://drupal.org/node/1708404. views_init(); - $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $type), 'views:' . $type, 'views'); + $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', $type), 'views:' . $type, 'views_info'); $this->factory = new DefaultFactory($this); $this->coreModules = views_core_modules(); $this->defaults += array( diff --git a/lib/Drupal/views/Plugin/Type/WizardManager.php b/lib/Drupal/views/Plugin/Type/WizardManager.php new file mode 100644 index 000000000000..336c171c59e3 --- /dev/null +++ b/lib/Drupal/views/Plugin/Type/WizardManager.php @@ -0,0 +1,51 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Plugin\Type\WizardManager. + */ + +namespace Drupal\views\Plugin\Type; + +use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Component\Plugin\Factory\DefaultFactory; +use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; +use Drupal\Core\Plugin\Discovery\CacheDecorator; + +class WizardManager extends PluginManagerBase { + + /** + * A list of Drupal core modules. + * + * @var array + */ + protected $coreModules = array(); + + /** + * Constructs a WizardManager object. + */ + public function __construct() { + // @todo Remove this hack in http://drupal.org/node/1708404. + views_init(); + + $this->discovery = new CacheDecorator(new AnnotatedClassDiscovery('views', 'wizard'), 'views:wizard', 'views_info'); + $this->factory = new DefaultFactory($this); + + $this->coreModules = views_core_modules(); + } + + /** + * Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition(). + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + $module = isset($definition['module']) ? $definition['module'] : 'views'; + $module_dir = in_array($module, $this->coreModules) ? 'views' : $module; + + $definition += array( + 'module' => $module_dir, + ); + } + +} diff --git a/lib/Drupal/views/ViewsBundle.php b/lib/Drupal/views/ViewsBundle.php index a432e3563a34..7a85ff059640 100644 --- a/lib/Drupal/views/ViewsBundle.php +++ b/lib/Drupal/views/ViewsBundle.php @@ -21,8 +21,16 @@ class ViewsBundle extends Bundle { */ public function build(ContainerBuilder $container) { foreach (ViewExecutable::getPluginTypes() as $type) { - $container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\Type\ViewsPluginManager') - ->addArgument($type); + if ($type == 'join') { + $container->register('plugin.manager.views.join', 'Drupal\views\Plugin\Type\JoinManager'); + } + elseif ($type == 'wizard') { + $container->register('plugin.manager.views.wizard', 'Drupal\views\Plugin\Type\WizardManager'); + } + else { + $container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\Type\PluginManager') + ->addArgument($type); + } } } -- GitLab