Issue #2022087 by damiankloip: Add module owner to plugin definition in AnnotatedClassDiscovery.
parent
b22c7a5b66
commit
0360c07ec1
|
@ -62,6 +62,39 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
|
|||
parent::__construct($plugin_namespaces, $annotation_namespaces, $plugin_definition_annotation_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinitions() {
|
||||
$definitions = parent::getDefinitions();
|
||||
foreach ($definitions as &$definition) {
|
||||
// Extract the module name from the class namespace if it's not set.
|
||||
if (!isset($definition['module'])) {
|
||||
$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\\\\(?<module>[\w]+)\\\\|', $namespace, $matches);
|
||||
|
||||
if (isset($matches['module'])) {
|
||||
return $matches['module'];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,7 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'label' => 'Apple',
|
||||
'color' => 'green',
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Apple',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
'banana' => array(
|
||||
'id' => 'banana',
|
||||
|
@ -39,18 +40,21 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'bread' => t('Banana bread'),
|
||||
),
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Banana',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
'cherry' => array(
|
||||
'id' => 'cherry',
|
||||
'label' => 'Cherry',
|
||||
'color' => 'red',
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
'orange' => array(
|
||||
'id' => 'orange',
|
||||
'label' => 'Orange',
|
||||
'color' => 'orange',
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Orange',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
$namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
|
||||
|
|
|
@ -32,11 +32,13 @@ class CustomAnnotationClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'id' => 'example_1',
|
||||
'custom' => 'John',
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\custom_annotation\Example1',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
'example_2' => array(
|
||||
'id' => 'example_2',
|
||||
'custom' => 'Paul',
|
||||
'class' => 'Drupal\plugin_test\Plugin\plugin_test\custom_annotation\Example2',
|
||||
'module' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
$root_namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
|
||||
|
|
Loading…
Reference in New Issue