Issue #2043379 by tim.plunkett: Allow plugins to be discovered in any directory.

8.0.x
Alex Pott 2013-07-25 00:57:30 +02:00
parent 45014004ad
commit d88a2be443
32 changed files with 140 additions and 52 deletions

View File

@ -28,7 +28,7 @@ class ActionManager extends PluginManagerBase {
* keyed by the corresponding namespace to look for plugin implementations. * keyed by the corresponding namespace to look for plugin implementations.
*/ */
public function __construct(\Traversable $namespaces) { 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->discovery = new AlterDecorator($this->discovery, 'action_info');
$this->factory = new ContainerFactory($this); $this->factory = new ContainerFactory($this);

View File

@ -31,7 +31,7 @@ class ArchiverManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with. * The module handler to invoke the alter hook with.
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { 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->alterInfo($module_handler, 'archiver_info');
$this->setCacheBackend($cache_backend, $language_manager, 'archiver_info'); $this->setCacheBackend($cache_backend, $language_manager, 'archiver_info');
} }

View File

@ -39,7 +39,7 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager
$annotation_namespaces = array( $annotation_namespaces = array(
'Drupal\Core\Condition\Annotation' => DRUPAL_ROOT . '/core/lib', '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');
} }
/** /**

View File

@ -112,7 +112,7 @@ class EntityManager extends PluginManagerBase {
$this->cache = $cache; $this->cache = $cache;
$this->languageManager = $language_manager; $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 InfoHookDecorator($this->discovery, 'entity_info');
$this->discovery = new AlterDecorator($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)); $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE));

View File

@ -45,7 +45,7 @@ class FieldTypePluginManager extends DefaultPluginManager {
$annotation_namespaces = array( $annotation_namespaces = array(
'Drupal\Core\Entity\Annotation' => DRUPAL_ROOT . '/core/lib', '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->alterInfo($module_handler, 'field_info');
$this->setCacheBackend($cache_backend, $language_manager, 'field_types'); $this->setCacheBackend($cache_backend, $language_manager, 'field_types');

View File

@ -59,7 +59,7 @@ class LocalActionManager extends DefaultPluginManager {
* The module handler. * The module handler.
*/ */
public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, ModuleHandlerInterface $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->controllerResolver = $controller_resolver;
$this->request = $request; $this->request = $request;

View File

@ -66,7 +66,7 @@ class LocalTaskManager extends DefaultPluginManager {
* The module handler.u * The module handler.u
*/ */
public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler) { 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->controllerResolver = $controller_resolver;
$this->request = $request; $this->request = $request;
$this->routeProvider = $route_provider; $this->routeProvider = $route_provider;

View File

@ -60,9 +60,10 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
protected $alterHook; 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; protected $subdir;
@ -83,11 +84,11 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
/** /**
* Creates the discovery object. * Creates the discovery object.
* *
* @param string $subdir * @param string|bool $subdir
* The plugin's subdirectory, for example views/filter. * The plugin's subdirectory, for example Plugin/views/filter.
* @param \Traversable $namespaces * @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths * 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 * @param array $annotation_namespaces
* (optional) The namespaces of classes that can be used as annotations. * (optional) The namespaces of classes that can be used as annotations.
* Defaults to an empty array. * Defaults to an empty array.

View File

@ -15,18 +15,14 @@ use Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery as ComponentAnnota
class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { 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 * @var string
*/ */
protected $owner; protected $subdir = '';
/**
* The plugin type, for example filter.
*
* @var string
*/
protected $type;
/** /**
* An object containing the namespaces to look for plugin implementations. * An object containing the namespaces to look for plugin implementations.
@ -39,11 +35,12 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
* Constructs an AnnotatedClassDiscovery object. * Constructs an AnnotatedClassDiscovery object.
* *
* @param string $subdir * @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 * @param \Traversable $root_namespaces
* An object that implements \Traversable which contains the root paths * 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.
* \Plugin\$subdir will be appended to each namespace. * If $subdir is not an empty string, it will be appended to each namespace.
* @param array $annotation_namespaces * @param array $annotation_namespaces
* (optional) The namespaces of classes that can be used as annotations. * (optional) The namespaces of classes that can be used as annotations.
* Defaults to an empty array. * Defaults to an empty array.
@ -52,7 +49,9 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
* Defaults to 'Drupal\Component\Annotation\Plugin'. * Defaults to 'Drupal\Component\Annotation\Plugin'.
*/ */
function __construct($subdir, \Traversable $root_namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = '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; $this->rootNamespacesIterator = $root_namespaces;
$annotation_namespaces += array( $annotation_namespaces += array(
'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib', 'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib',
@ -101,7 +100,10 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
protected function getPluginNamespaces() { protected function getPluginNamespaces() {
$plugin_namespaces = array(); $plugin_namespaces = array();
foreach ($this->rootNamespacesIterator as $namespace => $dir) { 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; return $plugin_namespaces;

View File

@ -52,7 +52,7 @@ class TypedDataManager extends DefaultPluginManager {
$annotation_namespaces = array( $annotation_namespaces = array(
'Drupal\Core\TypedData\Annotation' => DRUPAL_ROOT . '/core/lib', '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');
} }
/** /**

View File

@ -47,7 +47,7 @@ class ConstraintManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with. * The module handler to invoke the alter hook with.
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { 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->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions'));
$this->alterInfo($module_handler, 'validation_constraint'); $this->alterInfo($module_handler, 'validation_constraint');
$this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint'); $this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint');

View File

@ -38,7 +38,7 @@ class AggregatorPluginManager extends PluginManagerBase {
'Drupal\aggregator\Annotation' => DRUPAL_ROOT . '/core/modules/aggregator/lib', '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->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(Language::TYPE_INTERFACE)->id);
$this->factory = new DefaultFactory($this->discovery); $this->factory = new DefaultFactory($this->discovery);
} }

View File

@ -33,7 +33,7 @@ class BlockManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with. * The module handler to invoke the alter hook with.
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { 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->alterInfo($module_handler, 'block');
$this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins');
} }

View File

@ -34,7 +34,7 @@ class CKEditorPluginManager extends DefaultPluginManager {
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$annotation_namespaces = array('Drupal\ckeditor\Annotation' => $namespaces['Drupal\ckeditor']); $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->alterInfo($module_handler, 'ckeditor_plugin_info');
$this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugin'); $this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugin');
} }

View File

@ -30,7 +30,7 @@ class InPlaceEditorManager extends PluginManagerBase {
*/ */
public function __construct(\Traversable $namespaces) { public function __construct(\Traversable $namespaces) {
$annotation_namespaces = array('Drupal\edit\Annotation' => $namespaces['Drupal\edit']); $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 AlterDecorator($this->discovery, 'edit_editor');
$this->discovery = new CacheDecorator($this->discovery, 'edit:editor'); $this->discovery = new CacheDecorator($this->discovery, 'edit:editor');
$this->factory = new DefaultFactory($this->discovery); $this->factory = new DefaultFactory($this->discovery);

View File

@ -32,7 +32,7 @@ class EditorManager extends DefaultPluginManager {
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$annotation_namespaces = array('Drupal\editor\Annotation' => $namespaces['Drupal\editor']); $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->alterInfo($module_handler, 'editor_info');
$this->setCacheBackend($cache_backend, $language_manager, 'editor'); $this->setCacheBackend($cache_backend, $language_manager, 'editor');
} }

View File

@ -25,11 +25,8 @@ class SelectionPluginManager extends DefaultPluginManager {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { 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']);
$annotation_namespaces = array( $this->discovery = new AnnotatedClassDiscovery('Plugin/entity_reference/selection', $namespaces, $annotation_namespaces, 'Drupal\entity_reference\Annotation\EntityReferenceSelection');
'Drupal\entity_reference\Annotation' => $namespaces['Drupal\entity_reference']
);
$this->discovery = new AnnotatedClassDiscovery($this->subdir, $namespaces, $annotation_namespaces, 'Drupal\entity_reference\Annotation\EntityReferenceSelection');
// We're not using the parent constructor because we use a different factory // We're not using the parent constructor because we use a different factory
// method and don't need the derivative discovery decorator. // method and don't need the derivative discovery decorator.

View File

@ -46,7 +46,7 @@ class FormatterPluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); $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->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types');
$this->alterInfo($module_handler, 'field_formatter_info'); $this->alterInfo($module_handler, 'field_formatter_info');

View File

@ -46,7 +46,7 @@ class WidgetPluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) {
$annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); $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->setCacheBackend($cache_backend, $language_manager, 'field_widget_types');
$this->alterInfo($module_handler, 'field_widget_info'); $this->alterInfo($module_handler, 'field_widget_info');

View File

@ -31,7 +31,7 @@ class FilterPluginManager extends PluginManagerBase {
*/ */
public function __construct(\Traversable $namespaces) { public function __construct(\Traversable $namespaces) {
$annotation_namespaces = array('Drupal\filter\Annotation' => $namespaces['Drupal\filter']); $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'); $this->discovery = new AlterDecorator($this->discovery, 'filter_info');
$cache_key = 'filter_plugins:' . language(Language::TYPE_INTERFACE)->id; $cache_key = 'filter_plugins:' . language(Language::TYPE_INTERFACE)->id;
$cache_tags = array('filter_formats' => TRUE); $cache_tags = array('filter_formats' => TRUE);

View File

@ -22,7 +22,7 @@ class ImageEffectManager extends DefaultPluginManager {
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$annotation_namespaces = array('Drupal\image\Annotation' => $namespaces['Drupal\image']); $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->alterInfo($module_handler, 'image_effect_info');
$this->setCacheBackend($cache_backend, $language_manager, 'image_effect'); $this->setCacheBackend($cache_backend, $language_manager, 'image_effect');

View File

@ -31,7 +31,7 @@ class LayoutManager extends PluginManagerBase {
*/ */
public function __construct(\Traversable $namespaces) { public function __construct(\Traversable $namespaces) {
// Create layout plugin derivatives from declaratively defined layouts. // 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 DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));

View File

@ -28,7 +28,7 @@ class ResourcePluginManager extends PluginManagerBase {
*/ */
public function __construct(\Traversable $namespaces) { public function __construct(\Traversable $namespaces) {
// Create resource plugin derivatives from declaratively defined resources. // 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 DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new AlterDecorator($this->discovery, 'rest_resource'); $this->discovery = new AlterDecorator($this->discovery, 'rest_resource');
$this->discovery = new CacheDecorator($this->discovery, 'rest'); $this->discovery = new CacheDecorator($this->discovery, 'rest');

View File

@ -28,7 +28,7 @@ class ImageToolkitManager extends DefaultPluginManager {
* The language manager. * The language manager.
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $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'); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit');
} }

View File

@ -29,7 +29,7 @@ class PluginUIManager extends PluginManagerBase {
* keyed by the corresponding namespace to look for plugin implementations, * keyed by the corresponding namespace to look for plugin implementations,
*/ */
public function __construct(\Traversable $namespaces) { 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 DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new AlterDecorator($this->discovery, 'plugin_ui'); $this->discovery = new AlterDecorator($this->discovery, 'plugin_ui');
$this->discovery = new CacheDecorator($this->discovery, 'plugin_ui'); $this->discovery = new CacheDecorator($this->discovery, 'plugin_ui');

View File

@ -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')); $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->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces);
$this->emptyDiscovery = new AnnotatedClassDiscovery('non_existing_module/non_existing_plugin_type', $namespaces); $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
} }
} }

View File

@ -46,8 +46,8 @@ class CustomAnnotationClassDiscoveryTest extends DiscoveryTestBase {
'Drupal\plugin_test\Plugin\Annotation' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib', '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->discovery = new AnnotatedClassDiscovery('Plugin/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->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
} }
} }

View File

@ -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);
}
}

View File

@ -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 {}

View File

@ -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 {}

View File

@ -32,7 +32,7 @@ class TipPluginManager extends DefaultPluginManager {
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) {
$annotation_namespaces = array('Drupal\tour\Annotation' => $namespaces['Drupal\tour']); $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->alterInfo($module_handler, 'tour_tips_info');
$this->setCacheBackend($cache_backend, $language_manager, 'tour'); $this->setCacheBackend($cache_backend, $language_manager, 'tour');

View File

@ -31,7 +31,7 @@ class ViewsPluginManager extends PluginManagerBase {
* keyed by the corresponding namespace to look for plugin implementations, * keyed by the corresponding namespace to look for plugin implementations,
*/ */
public function __construct($type, \Traversable $namespaces) { 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 DerivativeDiscoveryDecorator($this->discovery);
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));
$this->discovery = new AlterDecorator($this->discovery, 'views_plugins_' . $type); $this->discovery = new AlterDecorator($this->discovery, 'views_plugins_' . $type);