diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index 84cb550..d15696a 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -17,19 +17,24 @@ 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 + * * @param array $plugin_namespaces * An array of paths keyed by it's corresponding namespaces. */ - function __construct($owner, $type, $root_namespaces = NULL, array $plugin_namespaces = array()) { + function __construct($owner, $type, array $root_namespaces = array(), array $plugin_namespaces = array()) { $this->owner = $owner; $this->type = $type; $this->rootNamespaces = $root_namespaces; - $this->pluginNamespaces = $plugin_namespaces; $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'); + parent::__construct($plugin_namespaces, $annotation_namespaces, 'Drupal\Core\Annotation\Plugin'); } /** @@ -41,7 +46,7 @@ function __construct($owner, $type, $root_namespaces = NULL, array $plugin_names * lifetime of a plugin manager. */ protected function getPluginNamespaces() { - if (!empty($this->plugin_namespaces)) { + if (!empty($this->pluginNamespaces)) { return parent::getPluginNamespaces(); } $plugin_namespaces = array(); 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 eb08a1a..11ae638 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 @@ -57,5 +57,20 @@ public function setUp() { $this->discovery = new AnnotatedClassDiscovery('plugin_test', 'fruit', $namespaces); $this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module', 'non_existing_plugin_type', $namespaces); } + + /** + * Tests AnnotatedClassDiscovery without root namespaces. + */ + public function testAnnotatedClassDiscoveryWithPluginNamespaces() { + $plugin_namespaces = array(); + $plugin_namespaces['Drupal\\plugin_test\\Plugin\\plugin_test\\fruit'] = array(DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'); + $this->discovery = new AnnotatedClassDiscovery('plugin_test', 'fruit', array(), $plugin_namespaces); + $plugin_namespaces = array(); + $plugin_namespaces['Drupal\\plugin_test\\Plugin\\non_existing_module\\non_existing_plugin_type'] = array(DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'); + $this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module', 'non_existing_plugin_type', array(), $plugin_namespaces); + + $this->testDiscoveryInterface(); + } + }