diff --git a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php index 201b207..58255b9 100644 --- a/core/lib/Drupal/Component/Plugin/PluginManagerBase.php +++ b/core/lib/Drupal/Component/Plugin/PluginManagerBase.php @@ -8,6 +8,8 @@ namespace Drupal\Component\Plugin; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; +use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Component\Utility\String; /** * Base class for plugin managers. @@ -38,6 +40,25 @@ protected $mapper; /** + * Defines an interface each plugin should implement. + * + * @var string|null + */ + protected $interface; + + /** + * Constructs a new plugin manager. + * + * @param string|null $plugin_interface + * (optional) The interface each plugin should implement. + */ + public function __construct($plugin_interface = NULL) { + if ($plugin_interface) { + $this->interface = $plugin_interface; + } + } + + /** * {@inheritdoc} */ public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { @@ -55,6 +76,7 @@ public function getDefinitions() { * {@inheritdoc} */ public function createInstance($plugin_id, array $configuration = array()) { + $this->enforcePluginInterface($plugin_id); return $this->factory->createInstance($plugin_id, $configuration); } @@ -65,4 +87,24 @@ public function getInstance(array $options) { return $this->mapper->getInstance($options); } + /** + * Enforces that a plugin implements the required interface. + * + * @param string $plugin_id + * + * @throws \Drupal\Component\Plugin\Exception\PluginException + */ + protected function enforcePluginInterface($plugin_id) { + // If an interface is specified, enforce that the plugin implements it. + $plugin_definition = $this->getDefinition($plugin_id); + if ($this->interface && !is_subclass_of($plugin_definition['class'], $this->interface)) { + throw new PluginException(String::format('Plugin "@plugin_id" (@class) in @provider should implement interface @interface', array( + '@plugin_id' => $plugin_id, + '@class' => $plugin_definition['class'], + '@provider' => $plugin_definition['provider'], + '@interface' => is_array($this->interface) ? implode(', ', $this->interface) : $this->interface, + ))); + } + } + } diff --git a/core/lib/Drupal/Core/Action/ActionManager.php b/core/lib/Drupal/Core/Action/ActionManager.php index 2b4002d..1baf427 100644 --- a/core/lib/Drupal/Core/Action/ActionManager.php +++ b/core/lib/Drupal/Core/Action/ActionManager.php @@ -22,11 +22,6 @@ class ActionManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Action\ActionInterface'; - - /** * Constructs a new class instance. * * @param \Traversable $namespaces @@ -38,7 +33,7 @@ class ActionManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Action', $namespaces, $module_handler, 'Drupal\Core\Annotation\Action'); + parent::__construct('Plugin/Action', $namespaces, $module_handler, 'Drupal\Core\Action\ActionInterface', 'Drupal\Core\Annotation\Action'); $this->alterInfo('action_info'); $this->setCacheBackend($cache_backend, 'action_info'); } diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index ac11937..9263bd3 100644 --- a/core/lib/Drupal/Core/Archiver/ArchiverManager.php +++ b/core/lib/Drupal/Core/Archiver/ArchiverManager.php @@ -22,11 +22,6 @@ class ArchiverManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Archiver\ArchiverInterface'; - - /** * Constructs a ArchiverManager object. * * @param \Traversable $namespaces @@ -38,7 +33,7 @@ class ArchiverManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\Annotation\Archiver'); + parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', 'Drupal\Core\Archiver\Annotation\Archiver'); $this->alterInfo('archiver_info'); $this->setCacheBackend($cache_backend, 'archiver_info_plugins'); } diff --git a/core/lib/Drupal/Core/Block/BlockManager.php b/core/lib/Drupal/Core/Block/BlockManager.php index 05365be..8cde728 100644 --- a/core/lib/Drupal/Core/Block/BlockManager.php +++ b/core/lib/Drupal/Core/Block/BlockManager.php @@ -26,11 +26,6 @@ class BlockManager extends DefaultPluginManager implements BlockManagerInterface use ContextAwarePluginManagerTrait; /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Block\BlockPluginInterface'; - - /** * An array of all available modules and their data. * * @var array @@ -49,7 +44,7 @@ class BlockManager extends DefaultPluginManager implements BlockManagerInterface * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\Core\Block\Annotation\Block'); + parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\Core\Block\BlockPluginInterface', 'Drupal\Core\Block\Annotation\Block'); $this->alterInfo('block'); $this->setCacheBackend($cache_backend, 'block_plugins'); diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index d7f717e..c1e309a 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -28,11 +28,6 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager use ContextAwarePluginManagerTrait; /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Condition\ConditionInterface'; - - /** * Constructs a ConditionManager object. * * @param \Traversable $namespaces @@ -47,7 +42,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->alterInfo('condition_info'); $this->setCacheBackend($cache_backend, 'condition_plugins'); - parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\Annotation\Condition'); + parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\ConditionInterface', 'Drupal\Core\Condition\Annotation\Condition'); } /** diff --git a/core/lib/Drupal/Core/Display/VariantManager.php b/core/lib/Drupal/Core/Display/VariantManager.php index 384c484..b591508 100755 --- a/core/lib/Drupal/Core/Display/VariantManager.php +++ b/core/lib/Drupal/Core/Display/VariantManager.php @@ -20,11 +20,6 @@ class VariantManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Display\VariantInterface'; - - /** * Constructs a new VariantManager. * * @param \Traversable $namespaces @@ -36,7 +31,7 @@ class VariantManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/DisplayVariant', $namespaces, $module_handler, 'Drupal\Core\Display\Annotation\DisplayVariant'); + parent::__construct('Plugin/DisplayVariant', $namespaces, $module_handler, 'Drupal\Core\Display\VariantInterface', 'Drupal\Core\Display\Annotation\DisplayVariant'); $this->setCacheBackend($cache_backend, 'variant_plugins'); $this->alterInfo('display_variant_plugin'); diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 4c0ad20..2c586fa 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -47,11 +47,6 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa use StringTranslationTrait; /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Entity\EntityInterface'; - - /** * Extra fields by bundle. * * @var array @@ -176,7 +171,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa * The class resolver. */ public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, TranslationInterface $translation_manager, ClassResolverInterface $class_resolver, TypedDataManager $typed_data_manager) { - parent::__construct('Entity', $namespaces, $module_handler, 'Drupal\Core\Entity\Annotation\EntityType'); + parent::__construct('Entity', $namespaces, $module_handler, 'Drupal\Core\Entity\EntityInterface', 'Drupal\Core\Entity\Annotation\EntityType'); $this->setCacheBackend($cache, 'entity_type', array('entity_types' => TRUE)); $this->alterInfo('entity_type'); diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php index 3a7febd..f3fb059 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php @@ -20,11 +20,6 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePluginManagerInterface { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Field\FieldItemInterface'; - - /** * Constructs the FieldTypePluginManager object * * @param \Traversable $namespaces @@ -36,7 +31,7 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Field/FieldType', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldType'); + parent::__construct('Plugin/Field/FieldType', $namespaces, $module_handler, 'Drupal\Core\Field\FieldItemInterface', 'Drupal\Core\Field\Annotation\FieldType'); $this->alterInfo('field_info'); $this->setCacheBackend($cache_backend, 'field_types_plugins'); } diff --git a/core/lib/Drupal/Core/Field/FormatterPluginManager.php b/core/lib/Drupal/Core/Field/FormatterPluginManager.php index fc658ff..b7b297b 100644 --- a/core/lib/Drupal/Core/Field/FormatterPluginManager.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php @@ -20,11 +20,6 @@ class FormatterPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Field\FormatterInterface'; - - /** * An array of formatter options for each field type. * * @var array @@ -52,8 +47,7 @@ class FormatterPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager) { - - parent::__construct('Plugin/Field/FieldFormatter', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldFormatter'); + parent::__construct('Plugin/Field/FieldFormatter', $namespaces, $module_handler, 'Drupal\Core\Field\FormatterInterface', 'Drupal\Core\Field\Annotation\FieldFormatter'); $this->setCacheBackend($cache_backend, 'field_formatter_types_plugins'); $this->alterInfo('field_formatter_info'); diff --git a/core/lib/Drupal/Core/Field/WidgetPluginManager.php b/core/lib/Drupal/Core/Field/WidgetPluginManager.php index 8d525b1..8aa4434 100644 --- a/core/lib/Drupal/Core/Field/WidgetPluginManager.php +++ b/core/lib/Drupal/Core/Field/WidgetPluginManager.php @@ -20,11 +20,6 @@ class WidgetPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Field\WidgetInterface'; - - /** * The field type manager to define field. * * @var \Drupal\Core\Field\FieldTypePluginManagerInterface @@ -52,7 +47,7 @@ class WidgetPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldWidget'); + parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\WidgetInterface', 'Drupal\Core\Field\Annotation\FieldWidget'); $this->setCacheBackend($cache_backend, 'field_widget_types_plugins'); $this->alterInfo('field_widget_info'); diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php index eaa31f0..9c11427 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -25,11 +25,6 @@ class ImageToolkitManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\ImageToolkit\ImageToolkitInterface'; - - /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -68,7 +63,7 @@ class ImageToolkitManager extends DefaultPluginManager { * A logger instance. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger) { - parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit'); + parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\ImageToolkitInterface', 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit'); $this->setCacheBackend($cache_backend, 'image_toolkit_plugins'); $this->configFactory = $config_factory; diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php index 8a65376..dc4abaa 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationManager.php @@ -26,11 +26,6 @@ class ImageToolkitOperationManager extends DefaultPluginManager implements ImageToolkitOperationManagerInterface { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\ImageToolkit\ImageToolkitOperationInterface'; - - /** * A logger instance. * * @var \Psr\Log\LoggerInterface @@ -51,7 +46,7 @@ class ImageToolkitOperationManager extends DefaultPluginManager implements Image * A logger instance. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LoggerInterface $logger) { - parent::__construct('Plugin/ImageToolkit/Operation', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkitOperation'); + parent::__construct('Plugin/ImageToolkit/Operation', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\ImageToolkitOperationInterface', 'Drupal\Core\ImageToolkit\Annotation\ImageToolkitOperation'); $this->alterInfo('image_toolkit_operation'); $this->setCacheBackend($cache_backend, 'image_toolkit_operation_plugins'); diff --git a/core/lib/Drupal/Core/Mail/MailManager.php b/core/lib/Drupal/Core/Mail/MailManager.php index 102a012..20ca520 100644 --- a/core/lib/Drupal/Core/Mail/MailManager.php +++ b/core/lib/Drupal/Core/Mail/MailManager.php @@ -29,11 +29,6 @@ class MailManager extends DefaultPluginManager implements MailManagerInterface { use StringTranslationTrait; /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Mail\MailInterface'; - - /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -72,7 +67,7 @@ class MailManager extends DefaultPluginManager implements MailManagerInterface { * The string translation service. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, TranslationInterface $string_translation) { - parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Annotation\Mail'); + parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Mail\MailInterface', 'Drupal\Core\Annotation\Mail'); $this->alterInfo('mail_backend_info'); $this->setCacheBackend($cache_backend, 'mail_backend_plugins'); $this->configFactory = $config_factory; diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 53a9b5b..5f2dfa3 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -9,9 +9,6 @@ use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait; -use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Component\Utility\String; use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\PluginManagerInterface; @@ -19,7 +16,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Factory\ContainerFactory; @@ -85,13 +81,6 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt protected $defaults = array(); /** - * Defines an interface each plugin should implement. - * - * @var string - */ - protected $interface; - - /** * Creates the discovery object. * * @param string|bool $subdir @@ -101,11 +90,14 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt * keyed by the corresponding namespace to look for plugin implementations. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param string|null $plugin_interface + * (optional) The interface each plugin should implement. * @param string $plugin_definition_annotation_name * (optional) The name of the annotation that contains the plugin definition. * Defaults to 'Drupal\Component\Annotation\Plugin'. */ - public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { + public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_interface = NULL, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { + parent::__construct($plugin_interface); $this->subdir = $subdir; $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $plugin_definition_annotation_name); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); @@ -246,37 +238,8 @@ protected function findDefinitions() { if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('core', 'component')) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) { unset($definitions[$plugin_id]); } - $this->enforcePluginInterface($plugin_id, $plugin_definition); } return $definitions; } - /** - * Enforces that a plugin implements the required interface. - * - * @param string $plugin_id - * @param array $plugin_definition - * - * @throws \Drupal\Component\Plugin\Exception\PluginException - */ - protected function enforcePluginInterface($plugin_id, array $plugin_definition) { - // Make it possible to not specify an interface. - if (!isset($this->interface)) { - return; - } - // If there are multiple valid interfaces, check for at least one. - if (is_array($this->interface) && array_intersect(class_implements($plugin_definition['class']), $this->interface)) { - return; - } - elseif (is_string($this->interface) && is_subclass_of($plugin_definition['class'], $this->interface)) { - return; - } - throw new PluginException(String::format('Plugin "@plugin_id" (@class) in @provider should implement interface @interface', array( - '@plugin_id' => $plugin_id, - '@class' => $plugin_definition['class'], - '@provider' => $plugin_definition['provider'], - '@interface' => is_array($this->interface) ? implode(', ', $this->interface) : $this->interface, - ))); - } - } diff --git a/core/lib/Drupal/Core/Render/ElementInfoManager.php b/core/lib/Drupal/Core/Render/ElementInfoManager.php index a0264d2..fe94243 100644 --- a/core/lib/Drupal/Core/Render/ElementInfoManager.php +++ b/core/lib/Drupal/Core/Render/ElementInfoManager.php @@ -26,11 +26,6 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoManagerInterface { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Core\Render\Element\ElementInterface'; - - /** * Stores the available element information. * * @var array @@ -51,7 +46,7 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $this->setCacheBackend($cache_backend, 'element_info'); - parent::__construct('Element', $namespaces, $module_handler, 'Drupal\Core\Render\Annotation\RenderElement'); + parent::__construct('Element', $namespaces, $module_handler, 'Drupal\Core\Render\Element\ElementInterface', 'Drupal\Core\Render\Annotation\RenderElement'); } /** diff --git a/core/modules/aggregator/src/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/src/Plugin/AggregatorPluginManager.php index 1e5d4b6..e1cccc7 100644 --- a/core/modules/aggregator/src/Plugin/AggregatorPluginManager.php +++ b/core/modules/aggregator/src/Plugin/AggregatorPluginManager.php @@ -26,15 +26,6 @@ class AggregatorPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = array( - 'Drupal\aggregator\Plugin\FetcherInterface', - 'Drupal\aggregator\Plugin\ParserInterface', - 'Drupal\aggregator\Plugin\ProcessorInterface', - ); - - /** * Constructs a AggregatorPluginManager object. * * @param string $type @@ -53,8 +44,13 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa 'parser' => 'Drupal\aggregator\Annotation\AggregatorParser', 'processor' => 'Drupal\aggregator\Annotation\AggregatorProcessor', ); + $plugin_interfaces = array( + 'fetcher' => 'Drupal\aggregator\Plugin\FetcherInterface', + 'parser' => 'Drupal\aggregator\Plugin\ParserInterface', + 'processor' => 'Drupal\aggregator\Plugin\ProcessorInterface', + ); - parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $type_annotations[$type]); + parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $plugin_interfaces[$type], $type_annotations[$type]); $this->setCacheBackend($cache_backend, 'aggregator_' . $type . '_plugins'); } diff --git a/core/modules/ckeditor/src/CKEditorPluginManager.php b/core/modules/ckeditor/src/CKEditorPluginManager.php index c79c580..1f05833 100644 --- a/core/modules/ckeditor/src/CKEditorPluginManager.php +++ b/core/modules/ckeditor/src/CKEditorPluginManager.php @@ -28,11 +28,6 @@ class CKEditorPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\ckeditor\CKEditorPluginInterface'; - - /** * Constructs a CKEditorPluginManager object. * * @param \Traversable $namespaces @@ -44,7 +39,7 @@ class CKEditorPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/CKEditorPlugin', $namespaces, $module_handler, 'Drupal\ckeditor\Annotation\CKEditorPlugin'); + parent::__construct('Plugin/CKEditorPlugin', $namespaces, $module_handler, 'Drupal\ckeditor\CKEditorPluginInterface', 'Drupal\ckeditor\Annotation\CKEditorPlugin'); $this->alterInfo('ckeditor_plugin_info'); $this->setCacheBackend($cache_backend, 'ckeditor_plugins'); } diff --git a/core/modules/editor/src/Plugin/EditorManager.php b/core/modules/editor/src/Plugin/EditorManager.php index 332e4dc..da0081e 100644 --- a/core/modules/editor/src/Plugin/EditorManager.php +++ b/core/modules/editor/src/Plugin/EditorManager.php @@ -22,11 +22,6 @@ class EditorManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\editor\Plugin\EditorPluginInterface'; - - /** * Constructs an EditorManager object. * * @param \Traversable $namespaces @@ -38,7 +33,7 @@ class EditorManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Editor', $namespaces, $module_handler, 'Drupal\editor\Annotation\Editor'); + parent::__construct('Plugin/Editor', $namespaces, $module_handler, 'Drupal\editor\Plugin\EditorPluginInterface', 'Drupal\editor\Annotation\Editor'); $this->alterInfo('editor_info'); $this->setCacheBackend($cache_backend, 'editor_plugins'); } diff --git a/core/modules/filter/src/FilterPluginManager.php b/core/modules/filter/src/FilterPluginManager.php index 650d99a..8eb1144 100644 --- a/core/modules/filter/src/FilterPluginManager.php +++ b/core/modules/filter/src/FilterPluginManager.php @@ -23,11 +23,6 @@ class FilterPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\filter\Plugin\FilterInterface'; - - /** * Constructs a FilterPluginManager object. * * @param \Traversable $namespaces @@ -39,7 +34,7 @@ class FilterPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Filter', $namespaces, $module_handler, 'Drupal\filter\Annotation\Filter'); + parent::__construct('Plugin/Filter', $namespaces, $module_handler, 'Drupal\filter\Plugin\FilterInterface', 'Drupal\filter\Annotation\Filter'); $this->alterInfo('filter_info'); $this->setCacheBackend($cache_backend, 'filter_plugins', array('filter_formats' => TRUE)); } diff --git a/core/modules/image/src/ImageEffectManager.php b/core/modules/image/src/ImageEffectManager.php index 694bc3e..aa4c24b 100644 --- a/core/modules/image/src/ImageEffectManager.php +++ b/core/modules/image/src/ImageEffectManager.php @@ -25,11 +25,6 @@ class ImageEffectManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\image\ImageEffectInterface'; - - /** * Constructs a new ImageEffectManager. * * @param \Traversable $namespaces @@ -41,7 +36,7 @@ class ImageEffectManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, 'Drupal\image\Annotation\ImageEffect'); + parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, 'Drupal\image\ImageEffectInterface', 'Drupal\image\Annotation\ImageEffect'); $this->alterInfo('image_effect_info'); $this->setCacheBackend($cache_backend, 'image_effect_plugins'); diff --git a/core/modules/language/src/LanguageNegotiationMethodManager.php b/core/modules/language/src/LanguageNegotiationMethodManager.php index 14201b7..b263ed5 100644 --- a/core/modules/language/src/LanguageNegotiationMethodManager.php +++ b/core/modules/language/src/LanguageNegotiationMethodManager.php @@ -17,11 +17,6 @@ class LanguageNegotiationMethodManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\language\LanguageNegotiationMethodInterface'; - - /** * Constructs a new LanguageNegotiationMethodManager object. * * @param \Traversable $namespaces @@ -33,7 +28,7 @@ class LanguageNegotiationMethodManager extends DefaultPluginManager { * An object that implements ModuleHandlerInterface */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/LanguageNegotiation', $namespaces, $module_handler); + parent::__construct('Plugin/LanguageNegotiation', $namespaces, $module_handler, 'Drupal\language\LanguageNegotiationMethodInterface'); $this->cacheBackend = $cache_backend; $this->cacheKeyPrefix = 'language_negotiation_plugins'; $this->cacheKey = 'language_negotiation_plugins'; diff --git a/core/modules/migrate/src/Plugin/MigratePluginManager.php b/core/modules/migrate/src/Plugin/MigratePluginManager.php index 7cfe943..67cce89 100644 --- a/core/modules/migrate/src/Plugin/MigratePluginManager.php +++ b/core/modules/migrate/src/Plugin/MigratePluginManager.php @@ -30,17 +30,6 @@ class MigratePluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = array( - 'Drupal\migrate\Plugin\MigrateDestinationInterface', - 'Drupal\migrate\Plugin\MigrateProcessInterface', - 'Drupal\migrate\Plugin\MigrateSourceInterface', - 'Drupal\migrate\Plugin\MigrateIdMapInterface', - 'Drupal\migrate\Plugin\MigrateEntityDestinationFieldInterface', - ); - - /** * Constructs a MigratePluginManager object. * * @param string $type @@ -57,7 +46,15 @@ class MigratePluginManager extends DefaultPluginManager { * The annotation class name. */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\Component\Annotation\PluginID') { - parent::__construct("Plugin/migrate/$type", $namespaces, $module_handler, $annotation); + $plugin_interface_map = array( + 'destination' => 'Drupal\migrate\Plugin\MigrateDestinationInterface', + 'process' => 'Drupal\migrate\Plugin\MigrateProcessInterface', + 'source' => 'Drupal\migrate\Plugin\MigrateSourceInterface', + 'id_map' => 'Drupal\migrate\Plugin\MigrateIdMapInterface', + 'entity_field' => 'Drupal\migrate\Plugin\MigrateEntityDestinationFieldInterface', + ); + $plugin_interface = isset($plugin_interface_map[$type]) ? $plugin_interface_map[$type] : NULL; + parent::__construct("Plugin/migrate/$type", $namespaces, $module_handler, $plugin_interface, $annotation); $this->alterInfo('migrate_' . $type . '_info'); $this->setCacheBackend($cache_backend, 'migrate_plugins_' . $type); } diff --git a/core/modules/quickedit/src/Plugin/InPlaceEditorManager.php b/core/modules/quickedit/src/Plugin/InPlaceEditorManager.php index c6c937f..210f675 100644 --- a/core/modules/quickedit/src/Plugin/InPlaceEditorManager.php +++ b/core/modules/quickedit/src/Plugin/InPlaceEditorManager.php @@ -24,11 +24,6 @@ class InPlaceEditorManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\quickedit\Plugin\InPlaceEditorInterface'; - - /** * Constructs a InPlaceEditorManager object. * * @param \Traversable $namespaces @@ -40,7 +35,7 @@ class InPlaceEditorManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/InPlaceEditor', $namespaces, $module_handler, 'Drupal\quickedit\Annotation\InPlaceEditor'); + parent::__construct('Plugin/InPlaceEditor', $namespaces, $module_handler, 'Drupal\quickedit\Plugin\InPlaceEditorInterface', 'Drupal\quickedit\Annotation\InPlaceEditor'); $this->alterInfo('quickedit_editor'); $this->setCacheBackend($cache_backend, 'quickedit:editor'); } diff --git a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php index 4569df8..97594c4 100644 --- a/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/src/Plugin/Type/ResourcePluginManager.php @@ -22,11 +22,6 @@ class ResourcePluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\rest\Plugin\ResourceInterface'; - - /** * Constructs a new \Drupal\rest\Plugin\Type\ResourcePluginManager object. * * @param \Traversable $namespaces @@ -38,7 +33,7 @@ class ResourcePluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/rest/resource', $namespaces, $module_handler, 'Drupal\rest\Annotation\RestResource'); + parent::__construct('Plugin/rest/resource', $namespaces, $module_handler, 'Drupal\rest\Plugin\ResourceInterface', 'Drupal\rest\Annotation\RestResource'); $this->setCacheBackend($cache_backend, 'rest_plugins'); $this->alterInfo('rest_resource'); diff --git a/core/modules/search/src/SearchPluginManager.php b/core/modules/search/src/SearchPluginManager.php index c1cc34c..bad133a 100644 --- a/core/modules/search/src/SearchPluginManager.php +++ b/core/modules/search/src/SearchPluginManager.php @@ -17,11 +17,6 @@ class SearchPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\search\Plugin\SearchInterface'; - - /** * Constructs SearchPluginManager * * @param \Traversable $namespaces @@ -33,7 +28,7 @@ class SearchPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Search', $namespaces, $module_handler, 'Drupal\search\Annotation\SearchPlugin'); + parent::__construct('Plugin/Search', $namespaces, $module_handler, 'Drupal\search\Plugin\SearchInterface', 'Drupal\search\Annotation\SearchPlugin'); $this->setCacheBackend($cache_backend, 'search_plugins'); $this->alterInfo('search_plugin'); } diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/DefaultsTestPluginManager.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/DefaultsTestPluginManager.php index 68026e1..737ad91 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/DefaultsTestPluginManager.php +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/DefaultsTestPluginManager.php @@ -17,11 +17,6 @@ */ class DefaultsTestPluginManager extends DefaultPluginManager { - /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\Component\Plugin\PluginInspectionInterface'; - /** * Constructs a new DefaultsTestPluginManager instance. * @@ -36,6 +31,7 @@ public function __construct(ModuleHandlerInterface $module_handler) { $this->discovery = new StaticDiscovery(); $this->factory = new DefaultFactory($this); $this->moduleHandler = $module_handler; + $this->interface = 'Drupal\Component\Plugin\PluginInspectionInterface'; // Specify default values. $this->defaults = array( diff --git a/core/modules/tour/src/TipPluginManager.php b/core/modules/tour/src/TipPluginManager.php index 1a66bbb..bcd2c78 100644 --- a/core/modules/tour/src/TipPluginManager.php +++ b/core/modules/tour/src/TipPluginManager.php @@ -22,11 +22,6 @@ class TipPluginManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\tour\TipPluginInterface'; - - /** * Constructs a new TipPluginManager. * * @param \Traversable $namespaces @@ -38,7 +33,7 @@ class TipPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/tour/tip', $namespaces, $module_handler, 'Drupal\tour\Annotation\Tip'); + parent::__construct('Plugin/tour/tip', $namespaces, $module_handler, 'Drupal\tour\TipPluginInterface', 'Drupal\tour\Annotation\Tip'); $this->alterInfo('tour_tips_info'); $this->setCacheBackend($cache_backend, 'tour_plugins'); diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index 0024a30..00dc979 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -20,11 +20,6 @@ class ViewsHandlerManager extends DefaultPluginManager { /** - * {@inheritdoc} - */ - protected $interface = '\Drupal\views\Plugin\views\ViewsHandlerInterface'; - - /** * The views data cache. * * @var \Drupal\views\ViewsData @@ -57,7 +52,11 @@ class ViewsHandlerManager extends DefaultPluginManager { */ public function __construct($handler_type, \Traversable $namespaces, ViewsData $views_data, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($handler_type); - parent::__construct("Plugin/views/$handler_type", $namespaces, $module_handler, $plugin_definition_annotation_name); + $plugin_interface = 'Drupal\views\Plugin\views\join\ViewsHandlerInterface'; + if ($handler_type == 'join') { + $plugin_interface = 'Drupal\views\Plugin\views\join\JoinPluginInterface'; + } + parent::__construct("Plugin/views/$handler_type", $namespaces, $module_handler, $plugin_interface, $plugin_definition_annotation_name); $this->setCacheBackend($cache_backend, "views:$handler_type", array('extension' => array(TRUE, 'views'))); diff --git a/core/modules/views/src/Plugin/ViewsJoinManager.php b/core/modules/views/src/Plugin/ViewsJoinManager.php deleted file mode 100644 index 66411a1..0000000 --- a/core/modules/views/src/Plugin/ViewsJoinManager.php +++ /dev/null @@ -1,20 +0,0 @@ -defaults += array( 'parent' => 'parent', diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index 1917f4a..b66568f 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -33,7 +33,7 @@ services: class: Drupal\views\Plugin\ViewsHandlerManager arguments: [filter, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] plugin.manager.views.join: - class: Drupal\views\Plugin\ViewsJoinManager + class: Drupal\views\Plugin\ViewsHandlerManager arguments: [join, '@container.namespaces', '@views.views_data', '@cache.discovery', '@module_handler'] plugin.manager.views.pager: class: Drupal\views\Plugin\ViewsPluginManager diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index c1dba2e..2d6390c 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -246,7 +246,7 @@ protected function setupLocalTaskManager() { $this->manager = $this ->getMockBuilder('Drupal\Core\Menu\LocalTaskManager') ->disableOriginalConstructor() - ->setMethods(NULL) + ->setMethods(array('enforcePluginInterface')) ->getMock(); $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'controllerResolver'); diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 4b3652c..fd220a2 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -212,33 +212,33 @@ public function testCacheClearWithTags() { /** * Tests plugins with the proper interface. * - * @covers ::getDefinitions + * @covers ::createInstance * @covers ::enforcePluginInterface */ - public function testGetDefinitionsWithJustValidInterfaces() { + public function testCreateInstanceWithJustValidInterfaces() { $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); - $definitions = $plugin_manager->getDefinitions(); - $this->assertCount(2, $definitions); - $this->assertEquals($definitions, $this->expectedDefinitions); + foreach ($this->expectedDefinitions as $plugin_id => $definition) { + $plugin_manager->createInstance($plugin_id); + } } /** * Tests plugins without the proper interface. * - * @covers ::getDefinitions + * @covers ::createInstance * @covers ::enforcePluginInterface * * @expectedException \Drupal\Component\Plugin\Exception\PluginException * @expectedExceptionMessage Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) in plugin_test should implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface */ - public function testGetDefinitionsWithInvalidInterfaces() { + public function testCreateInstanceWithInvalidInterfaces() { $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $module_handler->expects($this->any()) ->method('moduleExists') ->with('plugin_test') - ->willReturn(FALSE); + ->willReturn(TRUE); $this->expectedDefinitions['kale'] = array( 'id' => 'kale', @@ -251,7 +251,7 @@ public function testGetDefinitionsWithInvalidInterfaces() { $this->expectedDefinitions['banana']['provider'] = 'plugin_test'; $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface'); - $plugin_manager->getDefinitions(); + $plugin_manager->createInstance('kale'); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php index d6c6384..407a916 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php +++ b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Plugin; use Drupal\Component\Plugin\Discovery\StaticDiscovery; +use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; @@ -37,6 +38,7 @@ public function __construct(\Traversable $namespaces, array $definitions, Module // discovery implementation, but StaticDiscovery lets us add some simple // mock plugins for unit testing. $this->discovery = new StaticDiscovery(); + $this->factory = new DefaultFactory($this->discovery); // Add the static definitions. foreach ($definitions as $key => $definition) {