diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index 377bf4a..715bbfe 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -84,6 +84,8 @@ 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)) { @@ -103,6 +105,7 @@ 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; } } @@ -114,6 +117,25 @@ 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() {