diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index 715bbfe..377bf4a 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -84,8 +84,6 @@ public function getDefinitions() { // Search for classes within all PSR-0 namespace locations. foreach ($this->getPluginNamespaces() as $namespace => $dirs) { - // Extract the module name from this namespace. - $module = $this->getModuleFromNamespace($namespace); foreach ($dirs as $dir) { $dir .= DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $namespace); if (file_exists($dir)) { @@ -105,7 +103,6 @@ public function getDefinitions() { // instead of requiring us to work with the annotation object. $definition = $annotation->get(); $definition['class'] = $class; - $definition['module'] = $module; $definitions[$definition['id']] = $definition; } } @@ -117,25 +114,6 @@ public function getDefinitions() { } /** - * Extracts a module name from a Drupal namespace. - * - * @param string $namespace - * The namespace to extract the module name from. - * - * @return string|null - * The matches module name, or NULL otherwise. - */ - protected function getModuleFromNamespace($namespace) { - preg_match('|^Drupal\\\\(?[\w]+)\\\\|', $namespace, $matches); - - if (isset($matches['module'])) { - return $matches['module']; - } - - return NULL; - } - - /** * Returns an array of PSR-0 namespaces to search for plugin classes. */ protected function getPluginNamespaces() { diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index 8a45afc..2d19517 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -65,6 +65,38 @@ function __construct($subdir, \Traversable $root_namespaces, $annotation_namespa /** * {@inheritdoc} */ + public function getDefinitions() { + $definitions = parent::getDefinitions(); + foreach ($definitions as &$definition) { + // Extract the module name from the class namespace. + $definition['module'] = $this->getModuleFromNamespace($definition['class']); + } + return $definitions; + } + + /** + * Extracts a module name from a Drupal namespace. + * + * @param string $namespace + * The namespace to extract the module name from. + * + * @return string|null + * The matches module name, or NULL otherwise. + */ + protected function getModuleFromNamespace($namespace) { + preg_match('|^Drupal\\\\(?[\w]+)\\\\|', $namespace, $matches); + + if (isset($matches['module'])) { + return $matches['module']; + } + + return NULL; + } + + + /** + * {@inheritdoc} + */ protected function getPluginNamespaces() { $plugin_namespaces = array(); foreach ($this->rootNamespacesIterator as $namespace => $dir) {