Issue #2043379 by tim.plunkett: Allow plugins to be discovered in any directory.
parent
45014004ad
commit
d88a2be443
|
@ -28,7 +28,7 @@ class ActionManager extends PluginManagerBase {
|
|||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
$this->discovery = new AnnotatedClassDiscovery('Action', $namespaces, array(), 'Drupal\Core\Annotation\Action');
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/Action', $namespaces, array(), 'Drupal\Core\Annotation\Action');
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'action_info');
|
||||
|
||||
$this->factory = new ContainerFactory($this);
|
||||
|
|
|
@ -31,7 +31,7 @@ class ArchiverManager extends DefaultPluginManager {
|
|||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Archiver', $namespaces);
|
||||
parent::__construct('Plugin/Archiver', $namespaces);
|
||||
$this->alterInfo($module_handler, 'archiver_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'archiver_info');
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager
|
|||
$annotation_namespaces = array(
|
||||
'Drupal\Core\Condition\Annotation' => DRUPAL_ROOT . '/core/lib',
|
||||
);
|
||||
parent::__construct('Condition', $namespaces, $annotation_namespaces, 'Drupal\Core\Condition\Annotation\Condition');
|
||||
parent::__construct('Plugin/Condition', $namespaces, $annotation_namespaces, 'Drupal\Core\Condition\Annotation\Condition');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,7 +112,7 @@ class EntityManager extends PluginManagerBase {
|
|||
$this->cache = $cache;
|
||||
$this->languageManager = $language_manager;
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery('Core/Entity', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/Core/Entity', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
|
||||
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_info');
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'entity_info');
|
||||
$this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE));
|
||||
|
|
|
@ -45,7 +45,7 @@ class FieldTypePluginManager extends DefaultPluginManager {
|
|||
$annotation_namespaces = array(
|
||||
'Drupal\Core\Entity\Annotation' => DRUPAL_ROOT . '/core/lib',
|
||||
);
|
||||
parent::__construct('field/field_type', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\FieldType');
|
||||
parent::__construct('Plugin/field/field_type', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\FieldType');
|
||||
$this->alterInfo($module_handler, 'field_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'field_types');
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class LocalActionManager extends DefaultPluginManager {
|
|||
* The module handler.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Menu\LocalAction', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalAction');
|
||||
parent::__construct('Plugin/Menu/LocalAction', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalAction');
|
||||
|
||||
$this->controllerResolver = $controller_resolver;
|
||||
$this->request = $request;
|
||||
|
|
|
@ -66,7 +66,7 @@ class LocalTaskManager extends DefaultPluginManager {
|
|||
* The module handler.u
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Menu\LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask');
|
||||
parent::__construct('Plugin/Menu/LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask');
|
||||
$this->controllerResolver = $controller_resolver;
|
||||
$this->request = $request;
|
||||
$this->routeProvider = $route_provider;
|
||||
|
|
|
@ -60,9 +60,10 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
|
|||
protected $alterHook;
|
||||
|
||||
/**
|
||||
* The plugin's subdirectory, for example views/filter.
|
||||
* The subdirectory within a namespace to look for plugins, or FALSE if the
|
||||
* plugins are in the top level of the namespace.
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
protected $subdir;
|
||||
|
||||
|
@ -83,11 +84,11 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
|
|||
/**
|
||||
* Creates the discovery object.
|
||||
*
|
||||
* @param string $subdir
|
||||
* The plugin's subdirectory, for example views/filter.
|
||||
* @param string|bool $subdir
|
||||
* The plugin's subdirectory, for example Plugin/views/filter.
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param array $annotation_namespaces
|
||||
* (optional) The namespaces of classes that can be used as annotations.
|
||||
* Defaults to an empty array.
|
||||
|
|
|
@ -15,18 +15,14 @@ use Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery as ComponentAnnota
|
|||
class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
|
||||
|
||||
/**
|
||||
* The module name that defines the plugin type.
|
||||
* The subdirectory within a namespace to look for plugins.
|
||||
*
|
||||
* If the plugins are in the top level of the namespace and not within a
|
||||
* subdirectory, set this to an empty string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $owner;
|
||||
|
||||
/**
|
||||
* The plugin type, for example filter.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
protected $subdir = '';
|
||||
|
||||
/**
|
||||
* An object containing the namespaces to look for plugin implementations.
|
||||
|
@ -39,11 +35,12 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
|
|||
* Constructs an AnnotatedClassDiscovery object.
|
||||
*
|
||||
* @param string $subdir
|
||||
* The plugin's subdirectory, for example views/filter.
|
||||
* Either the plugin's subdirectory, for example 'Plugin/views/filter', or
|
||||
* empty string if plugins are located at the top level of the namespace.
|
||||
* @param \Traversable $root_namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations,
|
||||
* \Plugin\$subdir will be appended to each namespace.
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* If $subdir is not an empty string, it will be appended to each namespace.
|
||||
* @param array $annotation_namespaces
|
||||
* (optional) The namespaces of classes that can be used as annotations.
|
||||
* Defaults to an empty array.
|
||||
|
@ -52,7 +49,9 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
|
|||
* Defaults to 'Drupal\Component\Annotation\Plugin'.
|
||||
*/
|
||||
function __construct($subdir, \Traversable $root_namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') {
|
||||
$this->subdir = str_replace('/', '\\', $subdir);
|
||||
if ($subdir) {
|
||||
$this->subdir = str_replace('/', '\\', $subdir);
|
||||
}
|
||||
$this->rootNamespacesIterator = $root_namespaces;
|
||||
$annotation_namespaces += array(
|
||||
'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib',
|
||||
|
@ -101,7 +100,10 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
|
|||
protected function getPluginNamespaces() {
|
||||
$plugin_namespaces = array();
|
||||
foreach ($this->rootNamespacesIterator as $namespace => $dir) {
|
||||
$plugin_namespaces["$namespace\\Plugin\\{$this->subdir}"] = array($dir);
|
||||
if ($this->subdir) {
|
||||
$namespace .= "\\{$this->subdir}";
|
||||
}
|
||||
$plugin_namespaces[$namespace] = array($dir);
|
||||
}
|
||||
|
||||
return $plugin_namespaces;
|
||||
|
|
|
@ -52,7 +52,7 @@ class TypedDataManager extends DefaultPluginManager {
|
|||
$annotation_namespaces = array(
|
||||
'Drupal\Core\TypedData\Annotation' => DRUPAL_ROOT . '/core/lib',
|
||||
);
|
||||
parent::__construct('DataType', $namespaces, $annotation_namespaces, 'Drupal\Core\TypedData\Annotation\DataType');
|
||||
parent::__construct('Plugin/DataType', $namespaces, $annotation_namespaces, 'Drupal\Core\TypedData\Annotation\DataType');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ class ConstraintManager extends DefaultPluginManager {
|
|||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Validation/Constraint', $namespaces);
|
||||
parent::__construct('Plugin/Validation/Constraint', $namespaces);
|
||||
$this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions'));
|
||||
$this->alterInfo($module_handler, 'validation_constraint');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint');
|
||||
|
|
|
@ -38,7 +38,7 @@ class AggregatorPluginManager extends PluginManagerBase {
|
|||
'Drupal\aggregator\Annotation' => DRUPAL_ROOT . '/core/modules/aggregator/lib',
|
||||
);
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery("aggregator/$type", $namespaces, $annotation_namespaces, $type_annotations[$type]);
|
||||
$this->discovery = new AnnotatedClassDiscovery("Plugin/aggregator/$type", $namespaces, $annotation_namespaces, $type_annotations[$type]);
|
||||
$this->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(Language::TYPE_INTERFACE)->id);
|
||||
$this->factory = new DefaultFactory($this->discovery);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class BlockManager extends DefaultPluginManager {
|
|||
* The module handler to invoke the alter hook with.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Block', $namespaces);
|
||||
parent::__construct('Plugin/Block', $namespaces);
|
||||
$this->alterInfo($module_handler, 'block');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'block_plugins');
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
$annotation_namespaces = array('Drupal\ckeditor\Annotation' => $namespaces['Drupal\ckeditor']);
|
||||
parent::__construct('CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin');
|
||||
parent::__construct('Plugin/CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin');
|
||||
$this->alterInfo($module_handler, 'ckeditor_plugin_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugin');
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class InPlaceEditorManager extends PluginManagerBase {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
$annotation_namespaces = array('Drupal\edit\Annotation' => $namespaces['Drupal\edit']);
|
||||
$this->discovery = new AnnotatedClassDiscovery('InPlaceEditor', $namespaces, $annotation_namespaces, 'Drupal\edit\Annotation\InPlaceEditor');
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/InPlaceEditor', $namespaces, $annotation_namespaces, 'Drupal\edit\Annotation\InPlaceEditor');
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'edit_editor');
|
||||
$this->discovery = new CacheDecorator($this->discovery, 'edit:editor');
|
||||
$this->factory = new DefaultFactory($this->discovery);
|
||||
|
|
|
@ -32,7 +32,7 @@ class EditorManager extends DefaultPluginManager {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
$annotation_namespaces = array('Drupal\editor\Annotation' => $namespaces['Drupal\editor']);
|
||||
parent::__construct('Editor', $namespaces, $annotation_namespaces, 'Drupal\editor\Annotation\Editor');
|
||||
parent::__construct('Plugin/Editor', $namespaces, $annotation_namespaces, 'Drupal\editor\Annotation\Editor');
|
||||
$this->alterInfo($module_handler, 'editor_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'editor');
|
||||
}
|
||||
|
|
|
@ -25,11 +25,8 @@ class SelectionPluginManager extends DefaultPluginManager {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
$this->subdir = 'entity_reference/selection';
|
||||
$annotation_namespaces = array(
|
||||
'Drupal\entity_reference\Annotation' => $namespaces['Drupal\entity_reference']
|
||||
);
|
||||
$this->discovery = new AnnotatedClassDiscovery($this->subdir, $namespaces, $annotation_namespaces, 'Drupal\entity_reference\Annotation\EntityReferenceSelection');
|
||||
$annotation_namespaces = array('Drupal\entity_reference\Annotation' => $namespaces['Drupal\entity_reference']);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/entity_reference/selection', $namespaces, $annotation_namespaces, 'Drupal\entity_reference\Annotation\EntityReferenceSelection');
|
||||
|
||||
// We're not using the parent constructor because we use a different factory
|
||||
// method and don't need the derivative discovery decorator.
|
||||
|
|
|
@ -46,7 +46,7 @@ class FormatterPluginManager extends DefaultPluginManager {
|
|||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
|
||||
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']);
|
||||
|
||||
parent::__construct('field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter');
|
||||
parent::__construct('Plugin/field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter');
|
||||
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types');
|
||||
$this->alterInfo($module_handler, 'field_formatter_info');
|
||||
|
|
|
@ -46,7 +46,7 @@ class WidgetPluginManager extends DefaultPluginManager {
|
|||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
|
||||
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']);
|
||||
|
||||
parent::__construct('field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget');
|
||||
parent::__construct('Plugin/field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget');
|
||||
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types');
|
||||
$this->alterInfo($module_handler, 'field_widget_info');
|
||||
|
|
|
@ -31,7 +31,7 @@ class FilterPluginManager extends PluginManagerBase {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
$annotation_namespaces = array('Drupal\filter\Annotation' => $namespaces['Drupal\filter']);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Filter', $namespaces, $annotation_namespaces, 'Drupal\filter\Annotation\Filter');
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/Filter', $namespaces, $annotation_namespaces, 'Drupal\filter\Annotation\Filter');
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'filter_info');
|
||||
$cache_key = 'filter_plugins:' . language(Language::TYPE_INTERFACE)->id;
|
||||
$cache_tags = array('filter_formats' => TRUE);
|
||||
|
|
|
@ -22,7 +22,7 @@ class ImageEffectManager extends DefaultPluginManager {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
$annotation_namespaces = array('Drupal\image\Annotation' => $namespaces['Drupal\image']);
|
||||
parent::__construct('ImageEffect', $namespaces, $annotation_namespaces, 'Drupal\image\Annotation\ImageEffect');
|
||||
parent::__construct('Plugin/ImageEffect', $namespaces, $annotation_namespaces, 'Drupal\image\Annotation\ImageEffect');
|
||||
|
||||
$this->alterInfo($module_handler, 'image_effect_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'image_effect');
|
||||
|
|
|
@ -31,7 +31,7 @@ class LayoutManager extends PluginManagerBase {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
// Create layout plugin derivatives from declaratively defined layouts.
|
||||
$this->discovery = new AnnotatedClassDiscovery('Layout', $namespaces);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/Layout', $namespaces);
|
||||
$this->discovery = new DerivativeDiscoveryDecorator($this->discovery);
|
||||
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class ResourcePluginManager extends PluginManagerBase {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
// Create resource plugin derivatives from declaratively defined resources.
|
||||
$this->discovery = new AnnotatedClassDiscovery('rest/resource', $namespaces);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/rest/resource', $namespaces);
|
||||
$this->discovery = new DerivativeDiscoveryDecorator($this->discovery);
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'rest_resource');
|
||||
$this->discovery = new CacheDecorator($this->discovery, 'rest');
|
||||
|
|
|
@ -28,7 +28,7 @@ class ImageToolkitManager extends DefaultPluginManager {
|
|||
* The language manager.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) {
|
||||
parent::__construct('ImageToolkit', $namespaces);
|
||||
parent::__construct('Plugin/ImageToolkit', $namespaces);
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit');
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class PluginUIManager extends PluginManagerBase {
|
|||
* keyed by the corresponding namespace to look for plugin implementations,
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces) {
|
||||
$this->discovery = new AnnotatedClassDiscovery('PluginUI', $namespaces);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/PluginUI', $namespaces);
|
||||
$this->discovery = new DerivativeDiscoveryDecorator($this->discovery);
|
||||
$this->discovery = new AlterDecorator($this->discovery, 'plugin_ui');
|
||||
$this->discovery = new CacheDecorator($this->discovery, 'plugin_ui');
|
||||
|
|
|
@ -58,8 +58,8 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
|||
),
|
||||
);
|
||||
$namespaces = new \ArrayObject(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);
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces);
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ class CustomAnnotationClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'Drupal\plugin_test\Plugin\Annotation' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib',
|
||||
);
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery('plugin_test/custom_annotation', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module/non_existing_plugin_type', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\system\Tests\Plugin\Discovery\CustomDirectoryAnnotatedClassDiscoveryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\system\Tests\Plugin\Discovery;
|
||||
|
||||
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
|
||||
|
||||
/**
|
||||
* Tests that plugins with annotated classes in a custom directory are correctly discovered.
|
||||
*/
|
||||
class CustomDirectoryAnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Custom directory annotation class discovery',
|
||||
'description' => 'Tests that plugins in a custom directory are correctly discovered using annotated classes.',
|
||||
'group' => 'Plugin API',
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->expectedDefinitions = array(
|
||||
'custom_example_1' => array(
|
||||
'id' => 'custom_example_1',
|
||||
'custom' => 'Tim',
|
||||
'class' => 'Drupal\plugin_test\CustomDirectoryExample1',
|
||||
'provider' => 'plugin_test',
|
||||
),
|
||||
'custom_example_2' => array(
|
||||
'id' => 'custom_example_2',
|
||||
'custom' => 'Meghan',
|
||||
'class' => 'Drupal\plugin_test\CustomDirectoryExample2',
|
||||
'provider' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
$namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
|
||||
$this->discovery = new AnnotatedClassDiscovery('', $namespaces);
|
||||
$empty_namespaces = new \ArrayObject();
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('', $empty_namespaces);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\plugin_test\CustomDirectoryExample1.
|
||||
*/
|
||||
|
||||
namespace Drupal\plugin_test;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Provides a test plugin within a custom directory.
|
||||
*
|
||||
* @Plugin(
|
||||
* id = "custom_example_1",
|
||||
* custom = "Tim"
|
||||
* )
|
||||
*/
|
||||
class CustomDirectoryExample1 {}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\plugin_test\CustomDirectoryExample2.
|
||||
*/
|
||||
|
||||
namespace Drupal\plugin_test;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Provides a test plugin within a custom directory.
|
||||
*
|
||||
* @Plugin(
|
||||
* id = "custom_example_2",
|
||||
* custom = "Meghan"
|
||||
* )
|
||||
*/
|
||||
class CustomDirectoryExample2 {}
|
|
@ -32,7 +32,7 @@ class TipPluginManager extends DefaultPluginManager {
|
|||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
|
||||
$annotation_namespaces = array('Drupal\tour\Annotation' => $namespaces['Drupal\tour']);
|
||||
parent::__construct('tour/tip', $namespaces, $annotation_namespaces, 'Drupal\tour\Annotation\Tip');
|
||||
parent::__construct('Plugin/tour/tip', $namespaces, $annotation_namespaces, 'Drupal\tour\Annotation\Tip');
|
||||
|
||||
$this->alterInfo($module_handler, 'tour_tips_info');
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'tour');
|
||||
|
|
|
@ -31,7 +31,7 @@ class ViewsPluginManager extends PluginManagerBase {
|
|||
* keyed by the corresponding namespace to look for plugin implementations,
|
||||
*/
|
||||
public function __construct($type, \Traversable $namespaces) {
|
||||
$this->discovery = new AnnotatedClassDiscovery("views/$type", $namespaces);
|
||||
$this->discovery = new AnnotatedClassDiscovery("Plugin/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);
|
||||
|
|
Loading…
Reference in New Issue