From 780b4392973ad76eb40c65bef84d3fb6e64de75f Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 28 Feb 2013 11:24:13 +0000 Subject: [PATCH] Issue #1836008 by dawehner, Berdir, alexpott, katbailey, effulgentsia, EclipseGc: Fixed Remove drupal_classloader() use in Drupal\Core\AnnotatedClassDiscovery. --- .../DerivativeDiscoveryDecorator.php | 5 --- .../Core/Condition/ConditionManager.php | 7 +++- core/lib/Drupal/Core/CoreBundle.php | 6 ++- core/lib/Drupal/Core/DrupalKernel.php | 28 ++++++++++--- core/lib/Drupal/Core/Entity/EntityManager.php | 13 +++---- .../Discovery/AnnotatedClassDiscovery.php | 39 ++++++++++--------- .../Core/Validation/ConstraintManager.php | 7 +++- core/modules/aggregator/aggregator.admin.inc | 3 +- core/modules/aggregator/aggregator.module | 3 +- .../Drupal/aggregator/AggregatorBundle.php | 26 +++++++++++++ .../aggregator/Plugin/FetcherManager.php | 10 ++++- .../block/lib/Drupal/block/BlockBundle.php | 3 +- .../Drupal/block/Plugin/Type/BlockManager.php | 9 +++-- .../Plugin/system/plugin_ui/BlockPluginUI.php | 5 ++- .../Drupal/ckeditor/CKEditorPluginManager.php | 22 +++-------- .../lib/Drupal/ckeditor/CkeditorBundle.php | 3 +- .../Tests/CKEditorPluginManagerTest.php | 3 +- .../Drupal/ckeditor/Tests/CKEditorTest.php | 2 +- .../edit/lib/Drupal/edit/EditBundle.php | 3 +- .../lib/Drupal/edit/Plugin/EditorManager.php | 7 +++- .../Drupal/edit/Tests/EditorSelectionTest.php | 6 ++- .../edit/Tests/MetadataGeneratorTest.php | 7 +++- .../editor/lib/Drupal/editor/EditorBundle.php | 3 +- .../Drupal/editor/Plugin/EditorManager.php | 21 +++------- .../Drupal/editor/Tests/EditorManagerTest.php | 3 +- .../EntityReferenceBundle.php | 3 +- .../Plugin/Type/SelectionPluginManager.php | 7 +++- .../field/lib/Drupal/field/FieldBundle.php | 6 ++- .../Type/Formatter/FormatterPluginManager.php | 7 +++- .../Type/Widget/WidgetPluginManager.php | 7 +++- .../layout/lib/Drupal/layout/LayoutBundle.php | 3 +- .../layout/Plugin/Type/LayoutManager.php | 7 +++- .../Tests/Condition/NodeConditionTest.php | 2 +- .../Plugin/Type/ResourcePluginManager.php | 7 +++- .../rest/lib/Drupal/rest/RestBundle.php | 3 +- .../lib/Drupal/system/Plugin/PluginUIBase.php | 8 +++- .../system/Plugin/Type/PluginUIManager.php | 7 +++- .../system/lib/Drupal/system/SystemBundle.php | 3 +- .../Discovery/AnnotatedClassDiscoveryTest.php | 7 ++-- .../Drupal/condition_test/FormController.php | 2 +- .../tour/lib/Drupal/tour/TipPluginManager.php | 21 +++------- .../tour/lib/Drupal/tour/TourBundle.php | 3 +- .../views/Plugin/ViewsPluginManager.php | 9 ++++- .../views/lib/Drupal/views/ViewsBundle.php | 3 +- 44 files changed, 215 insertions(+), 144 deletions(-) create mode 100644 core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php diff --git a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php index d7fc8d6613a..e245874d4c5 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php @@ -65,11 +65,6 @@ class DerivativeDiscoveryDecorator implements DiscoveryInterface { protected function getDerivatives(array $base_plugin_definitions) { $plugin_definitions = array(); foreach ($base_plugin_definitions as $base_plugin_id => $plugin_definition) { - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (isset($plugin_definition['module']) && !module_exists($plugin_definition['module'])) { - continue; - } - $derivative_fetcher = $this->getDerivativeFetcher($base_plugin_id, $plugin_definition); if ($derivative_fetcher) { $derivative_definitions = $derivative_fetcher->getDerivativeDefinitions($plugin_definition); diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index c7cdb60a472..2f4c060b1e6 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -23,9 +23,12 @@ class ConditionManager extends PluginManagerBase implements ExecutableManagerInt /** * Constructs aa ConditionManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('Core', 'Condition'); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('Core', 'Condition', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'condition_info'); $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 6f7ff31adfc..2968e7a0ae1 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -141,7 +141,8 @@ class CoreBundle extends Bundle { ->addMethodCall('setUserAgent', array('Drupal (+http://drupal.org/)')); // Register the EntityManager. - $container->register('plugin.manager.entity', 'Drupal\Core\Entity\EntityManager'); + $container->register('plugin.manager.entity', 'Drupal\Core\Entity\EntityManager') + ->addArgument('%container.namespaces%'); // The 'request' scope and service enable services to depend on the Request // object and get reconstructed when the request object changes (e.g., @@ -181,7 +182,8 @@ class CoreBundle extends Bundle { ->addArgument('slave'); $container->register('typed_data', 'Drupal\Core\TypedData\TypedDataManager') ->addMethodCall('setValidationConstraintManager', array(new Reference('validation.constraint'))); - $container->register('validation.constraint', 'Drupal\Core\Validation\ConstraintManager'); + $container->register('validation.constraint', 'Drupal\Core\Validation\ConstraintManager') + ->addArgument('%container.namespaces%'); // Add the user's storage for temporary, non-cache data. $container->register('lock', 'Drupal\Core\Lock\DatabaseLockBackend'); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index d56f5037c86..729ff78d4ac 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -168,7 +168,7 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { $module_list = $this->configStorage->read('system.module'); $this->moduleList = isset($module_list['enabled']) ? $module_list['enabled'] : array(); } - $this->registerModuleNamespaces($this->getModuleFileNames()); + $this->registerNamespaces($this->getModuleNamespaces($this->getModuleFileNames())); // Load each module's bundle class. foreach ($this->moduleList as $module => $weight) { @@ -295,7 +295,7 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { // from the container. $container_modules = $this->container->getParameter('container.modules'); $namespaces_before = $this->classLoader->getNamespaces(); - $this->registerModuleNamespaces($container_modules); + $this->registerNamespaces($this->getModuleNamespaces($container_modules)); // If 'container.modules' is wrong, the container must be rebuilt. if (!isset($this->moduleList)) { @@ -368,6 +368,13 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { $container = $this->getContainerBuilder(); $container->setParameter('container.bundles', $this->bundleClasses); $container->setParameter('container.modules', $this->getModuleFileNames()); + + // Get a list of namespaces and put it onto the container. + $namespaces = $this->getModuleNamespaces($this->getModuleFileNames()); + $namespaces['Drupal\Core'] = DRUPAL_ROOT . '/core/lib'; + $namespaces['Drupal\Component'] = DRUPAL_ROOT . '/core/lib'; + $container->setParameter('container.namespaces', $namespaces); + // Register synthetic services. $container->register('class_loader', 'Symfony\Component\ClassLoader\UniversalClassLoader')->setSynthetic(TRUE); $container->register('kernel', 'Symfony\Component\HttpKernel\KernelInterface')->setSynthetic(TRUE); @@ -453,11 +460,22 @@ class DrupalKernel extends Kernel implements DrupalKernelInterface { } /** - * Registers the namespace of each enabled module with the class loader. + * Gets the namespaces of each enabled module. */ - protected function registerModuleNamespaces($moduleFileNames) { + protected function getModuleNamespaces($moduleFileNames) { + $namespaces = array(); foreach ($moduleFileNames as $module => $filename) { - $this->classLoader->registerNamespace("Drupal\\$module", DRUPAL_ROOT . '/' . dirname($filename) . '/lib'); + $namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib'; + } + return $namespaces; + } + + /** + * Registers a list of namespaces. + */ + protected function registerNamespaces(array $namespaces = array()) { + foreach ($namespaces as $namespace => $dir) { + $this->classLoader->registerNamespace($namespace, $dir); } } } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 566b2ccf931..a0d7c0371b1 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -168,10 +168,13 @@ class EntityManager extends PluginManagerBase { /** * Constructs a new Entity plugin manager. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { + public function __construct(array $namespaces) { // Allow the plugin definition to be altered by hook_entity_info_alter(). - $this->discovery = new AnnotatedClassDiscovery('Core', 'Entity'); + $this->discovery = new AnnotatedClassDiscovery('Core', 'Entity', $namespaces); $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); @@ -186,12 +189,6 @@ class EntityManager extends PluginManagerBase { public function processDefinition(&$definition, $plugin_id) { parent::processDefinition($definition, $plugin_id); - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (!module_exists($definition['module'])) { - $definition = NULL; - return; - } - // Prepare entity schema fields SQL info for // Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery(). if (isset($definition['base_table'])) { diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index 0b387dc7e57..dca530641d7 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -16,32 +16,33 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { /** * Constructs an AnnotatedClassDiscovery object. + * + * @param string $owner + * The module name that defines the plugin type. + * @param string $type + * The plugin type, for example filter. + * @param array $root_namespaces + * Array of root paths keyed by the corresponding namespace to look for + * plugin implementations, \Plugin\$owner\$type will be appended to each + * namespace. + * + * @todo Figure out how to make the following comment FALSE. + * Drupal modules can be enabled (and therefore, namespaces registered) + * during the lifetime of a plugin manager. Passing $root_namespaces into + * the constructor means plugins in the new namespaces will not be available + * until the next request. Additionally when a namespace is unregistered, + * plugins will not be removed until the next request. */ - function __construct($owner, $type, $root_namespaces = NULL) { - $this->owner = $owner; - $this->type = $type; - $this->rootNamespaces = $root_namespaces; + function __construct($owner, $type, array $root_namespaces = array()) { $annotation_namespaces = array( 'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib', 'Drupal\Core\Annotation' => DRUPAL_ROOT . '/core/lib', ); - parent::__construct(array(), $annotation_namespaces, 'Drupal\Core\Annotation\Plugin'); - } - - /** - * Overrides Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery::getPluginNamespaces(). - * - * This is overridden rather than set in the constructor, because Drupal - * modules can be enabled (and therefore, namespaces registered) during the - * lifetime of a plugin manager. - */ - protected function getPluginNamespaces() { $plugin_namespaces = array(); - $root_namespaces = isset($this->rootNamespaces) ? $this->rootNamespaces : drupal_classloader()->getNamespaces(); - foreach ($root_namespaces as $namespace => $dirs) { - $plugin_namespaces["$namespace\\Plugin\\{$this->owner}\\{$this->type}"] = $dirs; + foreach ($root_namespaces as $namespace => $dir) { + $plugin_namespaces["$namespace\\Plugin\\{$owner}\\{$type}"] = array($dir); } - return $plugin_namespaces; + parent::__construct($plugin_namespaces, $annotation_namespaces, 'Drupal\Core\Annotation\Plugin'); } } diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index 5177f090b80..e0444ae268a 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -38,9 +38,12 @@ class ConstraintManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('Validation', 'Constraint'); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('Validation', 'Constraint', $namespaces); $this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions')); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); diff --git a/core/modules/aggregator/aggregator.admin.inc b/core/modules/aggregator/aggregator.admin.inc index f87d9a09d84..632f1ec0877 100644 --- a/core/modules/aggregator/aggregator.admin.inc +++ b/core/modules/aggregator/aggregator.admin.inc @@ -6,7 +6,6 @@ */ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Drupal\aggregator\Plugin\FetcherManager; use Drupal\aggregator\Plugin\Core\Entity\Feed; /** @@ -346,7 +345,7 @@ function aggregator_admin_form($form, $form_state) { aggregator_sanitize_configuration(); // Get all available fetchers. - $fetcher_manager = new FetcherManager(); + $fetcher_manager = drupal_container()->get('plugin.manager.aggregator.fetcher'); $fetchers = array(); foreach ($fetcher_manager->getDefinitions() as $id => $definition) { $label = $definition['title'] . ' ' . $definition['description'] . ''; diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 7298e4ca622..6e89fdec09f 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -5,7 +5,6 @@ * Used to aggregate syndicated content (RSS, RDF, and Atom). */ -use Drupal\aggregator\Plugin\FetcherManager; use Drupal\aggregator\Plugin\Core\Entity\Feed; /** @@ -450,7 +449,7 @@ function aggregator_refresh(Feed $feed) { list($fetcher, $parser, $processors) = _aggregator_get_variables(); // Fetch the feed. - $fetcher_manager = new FetcherManager(); + $fetcher_manager = drupal_container()->get('plugin.manager.aggregator.fetcher'); try { $success = $fetcher_manager->createInstance($fetcher)->fetch($feed); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php b/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php new file mode 100644 index 00000000000..9c97d9a4d62 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/AggregatorBundle.php @@ -0,0 +1,26 @@ +register('plugin.manager.aggregator.fetcher', 'Drupal\aggregator\Plugin\FetcherManager') + ->addArgument('%container.namespaces%'); + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php index fa63c23b387..be8fc79ee29 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/FetcherManager.php @@ -17,8 +17,14 @@ use Drupal\Core\Plugin\Discovery\CacheDecorator; */ class FetcherManager extends PluginManagerBase { - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('aggregator', 'fetcher'); + /** + * Constructs a FetcherManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. + */ + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('aggregator', 'fetcher', $namespaces); $this->discovery = new CacheDecorator($this->discovery, 'aggregator_fetcher:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); $this->factory = new DefaultFactory($this->discovery); } diff --git a/core/modules/block/lib/Drupal/block/BlockBundle.php b/core/modules/block/lib/Drupal/block/BlockBundle.php index a20d06a8a97..71dfd331bf4 100644 --- a/core/modules/block/lib/Drupal/block/BlockBundle.php +++ b/core/modules/block/lib/Drupal/block/BlockBundle.php @@ -20,7 +20,8 @@ class BlockBundle extends Bundle { */ public function build(ContainerBuilder $container) { // Register the BlockManager class with the dependency injection container. - $container->register('plugin.manager.block', 'Drupal\block\Plugin\Type\BlockManager'); + $container->register('plugin.manager.block', 'Drupal\block\Plugin\Type\BlockManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index 91951a937e8..d5dedb9b68c 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -26,9 +26,12 @@ class BlockManager extends PluginManagerBase { /** * Constructs a new \Drupal\block\Plugin\Type\BlockManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('block', 'block'); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('block', 'block', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'block'); $this->discovery = new CacheDecorator($this->discovery, 'block_plugins:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache_block', CacheBackendInterface::CACHE_PERMANENT, array('block')); @@ -37,7 +40,7 @@ class BlockManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::createInstance(). */ - public function createInstance($plugin_id, array $configuration = array(), Block $entity = NULl) { + public function createInstance($plugin_id, array $configuration = array(), Block $entity = NULL) { $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this->discovery); return new $plugin_class($configuration, $plugin_id, $this->discovery, $entity); } diff --git a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php index 740b3496414..5beb4826814 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php +++ b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php @@ -24,7 +24,7 @@ use Drupal\Core\Annotation\Translation; * "module" = @Translation("Modules") * }, * link_title = @Translation("Configure block"), - * manager = "Drupal\block\Plugin\Type\BlockManager", + * manager = "plugin.manager.block", * menu = TRUE, * path = "admin/structure/block/list", * suffix = "add", @@ -46,7 +46,8 @@ class BlockPluginUI extends PluginUIBase { // @todo Add an inline comment here. list($plugin, $theme) = explode(':', $this->getPluginId()); $plugin_definition = $this->getDefinition(); - $manager = new $plugin_definition['manager'](); + // @todo Find out how to let the manager be injected into the class. + $manager = drupal_container()->get($plugin_definition['manager']); $plugins = $manager->getDefinitions(); $form['#theme'] = 'system_plugin_ui_form'; $form['theme'] = array( diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index 57a3a4bad0b..55002418a54 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -23,10 +23,12 @@ class CKEditorPluginManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('ckeditor', 'plugin'); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('ckeditor', 'plugin', $namespaces); $this->discovery = new AlterDecorator($this->discovery, 'ckeditor_plugin_info'); $this->discovery = new CacheDecorator($this->discovery, 'ckeditor_plugin'); $this->factory = new DefaultFactory($this->discovery); @@ -141,18 +143,4 @@ class CKEditorPluginManager extends PluginManagerBase { } } } - - /** - * Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition(). - */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (!module_exists($definition['module'])) { - $definition = NULL; - return; - } - } - } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php index eb8af1291d7..151c23ad240 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CkeditorBundle.php @@ -20,7 +20,8 @@ class CKEditorBundle extends Bundle { * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { - $container->register('plugin.manager.ckeditor.plugin', 'Drupal\ckeditor\CKEditorPluginManager'); + $container->register('plugin.manager.ckeditor.plugin', 'Drupal\ckeditor\CKEditorPluginManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php index fc569107c60..b7383d74fcd 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php @@ -63,7 +63,7 @@ class CKEditorPluginManagerTest extends DrupalUnitTestBase { * Tests the enabling of plugins. */ function testEnabledPlugins() { - $this->manager = new CKEditorPluginManager(); + $this->manager = new CKEditorPluginManager($this->container->getParameter('container.namespaces')); $editor = entity_load('editor', 'filtered_html'); // Case 1: no CKEditor plugins. @@ -77,6 +77,7 @@ class CKEditorPluginManagerTest extends DrupalUnitTestBase { // variations of it, to cover all possible ways a plugin can be enabled) and // clear the editor manager's cache so it is picked up. $this->enableModules(array('ckeditor_test')); + $this->manager = new CKEditorPluginManager($this->container->getParameter('container.namespaces')); $this->manager->clearCachedDefinitions(); // Case 2: CKEditor plugins are available. diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php index a71a725452d..fbfb93b4c76 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -64,7 +64,7 @@ class CKEditorTest extends DrupalUnitTestBase { $editor->save(); // Create "CKEditor" text editor plugin instance. - $manager = new EditorManager(); + $manager = new EditorManager($this->container->getParameter('container.namespaces')); $this->ckeditor = $manager->createInstance('ckeditor'); } diff --git a/core/modules/edit/lib/Drupal/edit/EditBundle.php b/core/modules/edit/lib/Drupal/edit/EditBundle.php index f64c29b6463..fe5259421e2 100644 --- a/core/modules/edit/lib/Drupal/edit/EditBundle.php +++ b/core/modules/edit/lib/Drupal/edit/EditBundle.php @@ -20,7 +20,8 @@ class EditBundle extends Bundle { * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { - $container->register('plugin.manager.edit.editor', 'Drupal\edit\Plugin\EditorManager'); + $container->register('plugin.manager.edit.editor', 'Drupal\edit\Plugin\EditorManager') + ->addArgument('%container.namespaces%'); $container->register('access_check.edit.entity_field', 'Drupal\edit\Access\EditEntityFieldAccessCheck') ->addTag('access_check'); diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php b/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php index 66876a6cd6c..ce2d650ff66 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/EditorManager.php @@ -23,9 +23,12 @@ class EditorManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('edit', 'editor'); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('edit', 'editor', $namespaces); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'edit_editor'); $this->discovery = new CacheDecorator($this->discovery, 'edit:editor'); diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php index 199a5257ad3..fdddec0f3a8 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php @@ -40,7 +40,7 @@ class EditorSelectionTest extends EditTestBase { function setUp() { parent::setUp(); - $this->editorManager = new EditorManager(); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->editorSelector = new EditorSelector($this->editorManager); } @@ -108,7 +108,9 @@ class EditorSelectionTest extends EditTestBase { function testTextWysiwyg() { // Enable edit_test module so that the 'wysiwyg' Create.js PropertyEditor // widget becomes available. - $this->enableModules(array('edit_test'), FALSE); + $this->enableModules(array('edit_test')); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); + $this->editorSelector = new EditorSelector($this->editorManager); $field_name = 'field_textarea'; $this->createFieldWithInstance( diff --git a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php index 364e4e0dd2b..529d535ff21 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php @@ -58,7 +58,7 @@ class MetadataGeneratorTest extends EditTestBase { $this->installSchema('field_test', 'test_entity_revision'); - $this->editorManager = new EditorManager(); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->accessChecker = new MockEditEntityFieldAccessCheck(); $this->editorSelector = new EditorSelector($this->editorManager); $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); @@ -132,7 +132,10 @@ class MetadataGeneratorTest extends EditTestBase { // Enable edit_test module so that the WYSIWYG Create.js PropertyEditor // widget becomes available. - $this->enableModules(array('edit_test'), FALSE); + $this->enableModules(array('edit_test')); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); + $this->editorSelector = new EditorSelector($this->editorManager); + $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); // Create a rich text field. $field_name = 'field_rich'; diff --git a/core/modules/editor/lib/Drupal/editor/EditorBundle.php b/core/modules/editor/lib/Drupal/editor/EditorBundle.php index 1e4b86af4e9..03389983c7d 100644 --- a/core/modules/editor/lib/Drupal/editor/EditorBundle.php +++ b/core/modules/editor/lib/Drupal/editor/EditorBundle.php @@ -21,7 +21,8 @@ class EditorBundle extends Bundle { public function build(ContainerBuilder $container) { // Register the plugin manager for our plugin type with the dependency // injection container. - $container->register('plugin.manager.editor', 'Drupal\editor\Plugin\EditorManager'); + $container->register('plugin.manager.editor', 'Drupal\editor\Plugin\EditorManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php index 74a5eab068d..c267b5fd351 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php @@ -21,10 +21,12 @@ class EditorManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('editor', 'editor'); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('editor', 'editor', $namespaces); $this->discovery = new AlterDecorator($this->discovery, 'editor_info'); $this->discovery = new CacheDecorator($this->discovery, 'editor'); $this->factory = new DefaultFactory($this->discovery); @@ -92,17 +94,4 @@ class EditorManager extends PluginManagerBase { return $attachments; } - /** - * Overrides Drupal\Component\Plugin\PluginManagerBase::processDefinition(). - */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (!module_exists($definition['module'])) { - $definition = NULL; - return; - } - } - } diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php index 3a83b8ab9a0..567db78f03e 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php @@ -66,7 +66,7 @@ class EditorManagerTest extends DrupalUnitTestBase { * Tests the configurable text editor manager. */ function testManager() { - $this->editorManager = new EditorManager(); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); // Case 1: no text editor available: // - listOptions() should return an empty list of options @@ -79,6 +79,7 @@ class EditorManagerTest extends DrupalUnitTestBase { // Enable the Text Editor Test module, which has the Unicorn Editor and // clear the editor manager's cache so it is picked up. $this->enableModules(array('editor_test')); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->editorManager->clearCachedDefinitions(); // Case 2: a text editor available. diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php index e490441efdd..56bd7973705 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceBundle.php @@ -21,6 +21,7 @@ class EntityReferenceBundle extends Bundle { public function build(ContainerBuilder $container) { // Register the SelectionPluginManager class with the dependency injection // container. - $container->register('plugin.manager.entity_reference.selection', 'Drupal\entity_reference\Plugin\Type\SelectionPluginManager'); + $container->register('plugin.manager.entity_reference.selection', 'Drupal\entity_reference\Plugin\Type\SelectionPluginManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php index af91a2dc9b1..db3bd4790f2 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php @@ -22,9 +22,12 @@ class SelectionPluginManager extends PluginManagerBase { /** * Constructs a SelectionPluginManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->baseDiscovery = new AlterDecorator(new AnnotatedClassDiscovery('entity_reference', 'selection'), 'entity_reference_selection'); + public function __construct($namespaces) { + $this->baseDiscovery = new AlterDecorator(new AnnotatedClassDiscovery('entity_reference', 'selection', $namespaces), 'entity_reference_selection'); $this->discovery = new CacheDecorator($this->baseDiscovery, 'entity_reference_selection'); $this->factory = new ReflectionFactory($this); } diff --git a/core/modules/field/lib/Drupal/field/FieldBundle.php b/core/modules/field/lib/Drupal/field/FieldBundle.php index 7fd0ddf71b5..b491a9c8c0b 100644 --- a/core/modules/field/lib/Drupal/field/FieldBundle.php +++ b/core/modules/field/lib/Drupal/field/FieldBundle.php @@ -20,8 +20,10 @@ class FieldBundle extends Bundle { */ public function build(ContainerBuilder $container) { // Register the plugin managers for our plugin types with the dependency injection container. - $container->register('plugin.manager.field.widget', 'Drupal\field\Plugin\Type\Widget\WidgetPluginManager'); - $container->register('plugin.manager.field.formatter', 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager'); + $container->register('plugin.manager.field.widget', 'Drupal\field\Plugin\Type\Widget\WidgetPluginManager') + ->addArgument('%container.namespaces%'); + $container->register('plugin.manager.field.formatter', 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index c935c441ecd..424f2723102 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -30,9 +30,12 @@ class FormatterPluginManager extends PluginManagerBase { /** * Constructs a FormatterPluginManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('field', 'formatter'); + public function __construct($namespaces) { + $this->discovery = new AnnotatedClassDiscovery('field', 'formatter', $namespaces); $this->discovery = new FormatterLegacyDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'field_formatter_info'); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 2d2c6e2cf6a..7014accad30 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -31,9 +31,12 @@ class WidgetPluginManager extends PluginManagerBase { /** * Constructs a WidgetPluginManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('field', 'widget'); + public function __construct($namespaces) { + $this->discovery = new AnnotatedClassDiscovery('field', 'widget', $namespaces); $this->discovery = new WidgetLegacyDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'field_widget_info'); diff --git a/core/modules/layout/lib/Drupal/layout/LayoutBundle.php b/core/modules/layout/lib/Drupal/layout/LayoutBundle.php index 59b8513027e..c639da9f228 100644 --- a/core/modules/layout/lib/Drupal/layout/LayoutBundle.php +++ b/core/modules/layout/lib/Drupal/layout/LayoutBundle.php @@ -20,6 +20,7 @@ class LayoutBundle extends Bundle { */ public function build(ContainerBuilder $container) { // Register the LayoutManager class with the dependency injection container. - $container->register('plugin.manager.layout', 'Drupal\layout\Plugin\Type\LayoutManager'); + $container->register('plugin.manager.layout', 'Drupal\layout\Plugin\Type\LayoutManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php index 191a3171814..0dcb14c1db6 100644 --- a/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php @@ -24,10 +24,13 @@ class LayoutManager extends PluginManagerBase { /** * Overrides Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { + public function __construct($namespaces) { // Create layout plugin derivatives from declaratively defined layouts. - $this->discovery = new AnnotatedClassDiscovery('layout', 'layout'); + $this->discovery = new AnnotatedClassDiscovery('layout', 'layout', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); diff --git a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php index addc5c093f7..a8058f78061 100644 --- a/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/Condition/NodeConditionTest.php @@ -38,7 +38,7 @@ class NodeConditionTest extends DrupalUnitTestBase { * Tests conditions. */ function testConditions() { - $manager = new ConditionManager(); + $manager = new ConditionManager($this->container->getParameter('container.namespaces')); // Get some nodes of various types to check against. $page = entity_create('node', array('type' => 'page', 'title' => $this->randomName())); diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php index 1bafc062f70..ec5e31e1a12 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php @@ -19,10 +19,13 @@ class ResourcePluginManager extends PluginManagerBase { /** * Overrides Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { + public function __construct($namespaces) { // Create resource plugin derivatives from declaratively defined resources. - $this->discovery = new DerivativeDiscoveryDecorator(new AnnotatedClassDiscovery('rest', 'resource')); + $this->discovery = new DerivativeDiscoveryDecorator(new AnnotatedClassDiscovery('rest', 'resource', $namespaces)); $this->factory = new ReflectionFactory($this->discovery); } diff --git a/core/modules/rest/lib/Drupal/rest/RestBundle.php b/core/modules/rest/lib/Drupal/rest/RestBundle.php index 9d9360fc3cc..49a11692632 100644 --- a/core/modules/rest/lib/Drupal/rest/RestBundle.php +++ b/core/modules/rest/lib/Drupal/rest/RestBundle.php @@ -22,7 +22,8 @@ class RestBundle extends Bundle { public function build(ContainerBuilder $container) { // Register the resource manager class with the dependency injection // container. - $container->register('plugin.manager.rest', 'Drupal\rest\Plugin\Type\ResourcePluginManager'); + $container->register('plugin.manager.rest', 'Drupal\rest\Plugin\Type\ResourcePluginManager') + ->addArgument('%container.namespaces%'); $container->register('rest.route_subscriber', 'Drupal\rest\EventSubscriber\RouteSubscriber') ->addArgument(new Reference('plugin.manager.rest')) diff --git a/core/modules/system/lib/Drupal/system/Plugin/PluginUIBase.php b/core/modules/system/lib/Drupal/system/Plugin/PluginUIBase.php index f2c312df77e..dd890fd48a6 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/PluginUIBase.php +++ b/core/modules/system/lib/Drupal/system/Plugin/PluginUIBase.php @@ -22,7 +22,13 @@ abstract class PluginUIBase extends PluginBase implements PluginUIInterface { */ public function form($form, &$form_state) { $plugin_definition = $this->getDefinition(); - $manager = new $plugin_definition['manager'](); + // @todo Find out how to let the manager be injected into the class. + if (class_exists($plugin_definition['manager'])) { + $manager = new $plugin_definition['manager'](); + } + else { + $manager = drupal_container()->get($plugin_definition['manager']); + } $plugins = $manager->getDefinitions(); $rows = array(); diff --git a/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php b/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php index 069f2b23c21..dd7fca3036b 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php @@ -23,9 +23,12 @@ class PluginUIManager extends PluginManagerBase { /** * Constructs a \Drupal\system\Plugin\Type\PluginUIManager object. + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('system', 'plugin_ui'); + public function __construct($namespaces) { + $this->discovery = new AnnotatedClassDiscovery('system', 'plugin_ui', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'plugin_ui'); $this->discovery = new CacheDecorator($this->discovery, 'plugin_ui'); diff --git a/core/modules/system/lib/Drupal/system/SystemBundle.php b/core/modules/system/lib/Drupal/system/SystemBundle.php index 8662169c407..2b937c0785c 100644 --- a/core/modules/system/lib/Drupal/system/SystemBundle.php +++ b/core/modules/system/lib/Drupal/system/SystemBundle.php @@ -24,6 +24,7 @@ class SystemBundle extends Bundle { // Register the various system plugin manager classes with the dependency // injection container. - $container->register('plugin.manager.system.plugin_ui', 'Drupal\system\Plugin\Type\PluginUIManager'); + $container->register('plugin.manager.system.plugin_ui', 'Drupal\system\Plugin\Type\PluginUIManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php index 5f395e124a1..fb026e95f16 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php @@ -53,8 +53,9 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase { 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Orange', ), ); - $this->discovery = new AnnotatedClassDiscovery('plugin_test', 'fruit'); - $this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module', 'non_existing_plugin_type'); + $namespaces = array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'); + $this->discovery = new AnnotatedClassDiscovery('plugin_test', 'fruit', $namespaces); + $this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module', 'non_existing_plugin_type', $namespaces); } -} +} diff --git a/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php b/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php index 35a53255e44..03b918eceb2 100644 --- a/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php +++ b/core/modules/system/tests/modules/condition_test/lib/Drupal/condition_test/FormController.php @@ -33,7 +33,7 @@ class FormController implements FormInterface { * Provides a simple method the router can fire in order to invoke this form. */ public function getForm() { - $manager = new ConditionManager(); + $manager = new ConditionManager(drupal_container()->getParameter('container.namespaces')); $this->condition = $manager->createInstance('node_type'); return drupal_get_form($this); } diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php index 19732c1f200..b8603987a8b 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php @@ -20,10 +20,12 @@ class TipPluginManager extends PluginManagerBase { /** * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct() { - $this->discovery = new AnnotatedClassDiscovery('tour', 'tip'); - $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); + public function __construct(array $namespaces) { + $this->discovery = new AnnotatedClassDiscovery('tour', 'tip', $namespaces); $this->discovery = new CacheDecorator($this->discovery, 'tour'); $this->factory = new DefaultFactory($this->discovery); } @@ -37,17 +39,4 @@ class TipPluginManager extends PluginManagerBase { $plugin_class = DefaultFactory::getPluginClass($plugin_id, $this->discovery); return new $plugin_class($configuration, $plugin_id, $this->discovery, $bag); } - - /** - * Overrides \Drupal\Component\Plugin\PluginManagerBase::processDefinition(). - */ - public function processDefinition(&$definition, $plugin_id) { - parent::processDefinition($definition, $plugin_id); - - // @todo Remove this check once http://drupal.org/node/1780396 is resolved. - if (!module_exists($definition['module'])) { - $definition = NULL; - return; - } - } } diff --git a/core/modules/tour/lib/Drupal/tour/TourBundle.php b/core/modules/tour/lib/Drupal/tour/TourBundle.php index 6839645ae63..f1394822446 100644 --- a/core/modules/tour/lib/Drupal/tour/TourBundle.php +++ b/core/modules/tour/lib/Drupal/tour/TourBundle.php @@ -21,6 +21,7 @@ class TourBundle extends Bundle { public function build(ContainerBuilder $container) { // Register the plugin manager for our plugin type with the dependency // injection container. - $container->register('plugin.manager.tour.tip', 'Drupal\tour\TipPluginManager'); + $container->register('plugin.manager.tour.tip', 'Drupal\tour\TipPluginManager') + ->addArgument('%container.namespaces%'); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php index 14fc64a72d8..56633f84753 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php @@ -22,9 +22,14 @@ class ViewsPluginManager extends PluginManagerBase { /** * Constructs a ViewsPluginManager object. + * + * @param string $type + * The plugin type, for example filter. + * @param array $namespaces + * An array of paths keyed by it's corresponding namespaces. */ - public function __construct($type) { - $this->discovery = new AnnotatedClassDiscovery('views', $type); + public function __construct($type, array $namespaces = array()) { + $this->discovery = new AnnotatedClassDiscovery('views', $type, $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'views_plugins_' . $type); diff --git a/core/modules/views/lib/Drupal/views/ViewsBundle.php b/core/modules/views/lib/Drupal/views/ViewsBundle.php index ac035cb6d93..0b18d3f5b68 100644 --- a/core/modules/views/lib/Drupal/views/ViewsBundle.php +++ b/core/modules/views/lib/Drupal/views/ViewsBundle.php @@ -23,7 +23,8 @@ class ViewsBundle extends Bundle { public function build(ContainerBuilder $container) { foreach (ViewExecutable::getPluginTypes() as $type) { $container->register("plugin.manager.views.$type", 'Drupal\views\Plugin\ViewsPluginManager') - ->addArgument($type); + ->addArgument($type) + ->addArgument('%container.namespaces%'); } $container