diff --git a/core/core.services.yml b/core/core.services.yml index e8b6464..00392e1 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -605,7 +605,7 @@ services: - { name: event_subscriber } image.toolkit.manager: class: Drupal\Core\ImageToolkit\ImageToolkitManager - arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory'] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory', '@module_handler'] image.toolkit: class: Drupal\Core\ImageToolkit\ImageToolkitInterface factory_method: getDefaultToolkit diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index f446f37..e45fc87 100644 --- a/core/lib/Drupal/Core/Archiver/ArchiverManager.php +++ b/core/lib/Drupal/Core/Archiver/ArchiverManager.php @@ -31,8 +31,8 @@ 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('Plugin/Archiver', $namespaces, 'Drupal\Core\Archiver\Annotation\Archiver'); - $this->alterInfo($module_handler, 'archiver_info'); + parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\Annotation\Archiver'); + $this->alterInfo('archiver_info'); $this->setCacheBackend($cache_backend, $language_manager, 'archiver_info_plugins'); } diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 604fea4..4b4e659 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -33,10 +33,10 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $this->alterInfo($module_handler, 'condition_info'); + $this->alterInfo('condition_info'); $this->setCacheBackend($cache_backend, $language_manager, 'condition_plugins'); - parent::__construct('Plugin/Condition', $namespaces, 'Drupal\Core\Condition\Annotation\Condition'); + parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\Annotation\Condition'); } /** diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php index 75ea2fd..3a41a5e 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php @@ -41,8 +41,8 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Field/FieldType', $namespaces, 'Drupal\Core\Field\Annotation\FieldType'); - $this->alterInfo($module_handler, 'field_info'); + parent::__construct('Plugin/Field/FieldType', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldType'); + $this->alterInfo('field_info'); $this->setCacheBackend($cache_backend, $language_manager, 'field_types_plugins'); } diff --git a/core/lib/Drupal/Core/Field/FormatterPluginManager.php b/core/lib/Drupal/Core/Field/FormatterPluginManager.php index c30ab0e..8d37818 100644 --- a/core/lib/Drupal/Core/Field/FormatterPluginManager.php +++ b/core/lib/Drupal/Core/Field/FormatterPluginManager.php @@ -49,10 +49,10 @@ class FormatterPluginManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct('Plugin/Field/FieldFormatter', $namespaces, 'Drupal\Core\Field\Annotation\FieldFormatter'); + parent::__construct('Plugin/Field/FieldFormatter', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldFormatter'); $this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types_plugins'); - $this->alterInfo($module_handler, 'field_formatter_info'); + $this->alterInfo('field_formatter_info'); $this->fieldTypeManager = $field_type_manager; } diff --git a/core/lib/Drupal/Core/Field/WidgetPluginManager.php b/core/lib/Drupal/Core/Field/WidgetPluginManager.php index 5ca455a..47fedb1 100644 --- a/core/lib/Drupal/Core/Field/WidgetPluginManager.php +++ b/core/lib/Drupal/Core/Field/WidgetPluginManager.php @@ -48,10 +48,10 @@ class WidgetPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct('Plugin/Field/FieldWidget', $namespaces, 'Drupal\Core\Field\Annotation\FieldWidget'); + parent::__construct('Plugin/Field/FieldWidget', $namespaces, $module_handler, 'Drupal\Core\Field\Annotation\FieldWidget'); $this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types_plugins'); - $this->alterInfo($module_handler, 'field_widget_info'); + $this->alterInfo('field_widget_info'); $this->factory = new WidgetFactory($this); $this->fieldTypeManager = $field_type_manager; diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php index eceab87..5ec45ea 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; @@ -36,9 +37,11 @@ class ImageToolkitManager extends DefaultPluginManager { * The language manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ConfigFactoryInterface $config_factory) { - parent::__construct('Plugin/ImageToolkit', $namespaces, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit'); + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { + parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\Core\ImageToolkit\Annotation\ImageToolkit'); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit_plugins'); $this->configFactory = $config_factory; diff --git a/core/lib/Drupal/Core/Mail/MailManager.php b/core/lib/Drupal/Core/Mail/MailManager.php index 9f01281..3fe58f1 100644 --- a/core/lib/Drupal/Core/Mail/MailManager.php +++ b/core/lib/Drupal/Core/Mail/MailManager.php @@ -50,8 +50,8 @@ class MailManager extends DefaultPluginManager { * The configuration factory. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) { - parent::__construct('Plugin/Mail', $namespaces, 'Drupal\Core\Annotation\Mail'); - $this->alterInfo($module_handler, 'mail_backend_info'); + parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Annotation\Mail'); + $this->alterInfo('mail_backend_info'); $this->setCacheBackend($cache_backend, $language_manager, 'mail_backend_plugins'); $this->mailConfig = $config_factory->get('system.mail'); } diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php index 5141f5c..c585b00 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkManager.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkManager.php @@ -100,7 +100,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Mo $this->controllerResolver = $controller_resolver; $this->accessManager = $access_manager; $this->account = $account; - $this->alterInfo($module_handler, 'contextual_links_plugins'); + $this->moduleHandler = $module_handler; + $this->alterInfo('contextual_links_plugins'); $this->setCacheBackend($cache_backend, $language_manager, 'contextual_links_plugins'); } diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 79e40c9..457af4f 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -128,12 +128,12 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re $this->factory = new ContainerFactory($this); $this->routeProvider = $route_provider; $this->accessManager = $access_manager; + $this->moduleHandler = $module_handler; $this->account = $account; $this->controllerResolver = $controller_resolver; $this->request = $request; - $this->alterInfo($module_handler, 'menu_local_actions'); + $this->alterInfo('menu_local_actions'); $this->setCacheBackend($cache_backend, $language_manager, 'local_action_plugins', array('local_action' => TRUE)); - } /** diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index fde294f..5f954d1 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -137,7 +137,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re $this->routeBuilder = $route_builder; $this->accessManager = $access_manager; $this->account = $account; - $this->alterInfo($module_handler, 'local_tasks'); + $this->moduleHandler = $module_handler; + $this->alterInfo('local_tasks'); $this->setCacheBackend($cache, $language_manager, 'local_task_plugins', array('local_task' => TRUE)); } diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 6cbabf8..99abd89 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -106,15 +106,18 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. * @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, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { + public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->subdir = $subdir; $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $plugin_definition_annotation_name); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); + $this->moduleHandler = $module_handler; } /** @@ -150,13 +153,10 @@ public function setCacheBackend(CacheBackendInterface $cache_backend, LanguageMa /** * Initializes the alter hook. * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to invoke the alter hook with. * @param string $alter_hook * Name of the alter hook. */ - protected function alterInfo(ModuleHandlerInterface $module_handler, $alter_hook) { - $this->moduleHandler = $module_handler; + protected function alterInfo($alter_hook) { $this->alterHook = $alter_hook; } @@ -267,6 +267,13 @@ protected function findDefinitions() { if ($this->alterHook) { $this->moduleHandler->alter($this->alterHook, $definitions); } + // If this plugin was provided by a module that does not exist, remove the + // plugin definition. + foreach ($definitions as $plugin_id => $plugin_definition) { + if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], array('Core', 'Component')) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) { + unset($definitions[$plugin_id]); + } + } return $definitions; } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index f8c9ab4..ff77acb 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -45,11 +45,24 @@ class TypedDataManager extends DefaultPluginManager { */ protected $prototypes = array(); + /** + * Constructs a new TypedDataManager. + * + * @param \Traversable $namespaces + * An object that implements \Traversable which contains the root paths + * keyed by the corresponding namespace to look for plugin implementations. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $this->alterInfo($module_handler, 'data_type_info'); + $this->alterInfo('data_type_info'); $this->setCacheBackend($cache_backend, $language_manager, 'typed_data_types_plugins'); - parent::__construct('Plugin/DataType', $namespaces, 'Drupal\Core\TypedData\Annotation\DataType'); + parent::__construct('Plugin/DataType', $namespaces, $module_handler, 'Drupal\Core\TypedData\Annotation\DataType'); } /** diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index d2e84c7..54d2b4f 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -47,9 +47,9 @@ 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('Plugin/Validation/Constraint', $namespaces); + parent::__construct('Plugin/Validation/Constraint', $namespaces, $module_handler); $this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions')); - $this->alterInfo($module_handler, 'validation_constraint'); + $this->alterInfo('validation_constraint'); $this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint_plugins'); } diff --git a/core/modules/aggregator/aggregator.services.yml b/core/modules/aggregator/aggregator.services.yml index e486b54..335ed77 100644 --- a/core/modules/aggregator/aggregator.services.yml +++ b/core/modules/aggregator/aggregator.services.yml @@ -1,10 +1,10 @@ services: plugin.manager.aggregator.fetcher: class: Drupal\aggregator\Plugin\AggregatorPluginManager - arguments: [fetcher, '@container.namespaces', '@cache.cache', '@language_manager'] + arguments: [fetcher, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] plugin.manager.aggregator.parser: class: Drupal\aggregator\Plugin\AggregatorPluginManager - arguments: [parser, '@container.namespaces', '@cache.cache', '@language_manager'] + arguments: [parser, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] plugin.manager.aggregator.processor: class: Drupal\aggregator\Plugin\AggregatorPluginManager - arguments: [processor, '@container.namespaces', '@cache.cache', '@language_manager'] + arguments: [processor, '@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php index 5f65c98..717d41c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php @@ -8,6 +8,7 @@ namespace Drupal\aggregator\Plugin; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; @@ -28,15 +29,17 @@ class AggregatorPluginManager extends DefaultPluginManager { * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { + public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $type_annotations = array( 'fetcher' => 'Drupal\aggregator\Annotation\AggregatorFetcher', 'parser' => 'Drupal\aggregator\Annotation\AggregatorParser', 'processor' => 'Drupal\aggregator\Annotation\AggregatorProcessor', ); - parent::__construct("Plugin/aggregator/$type", $namespaces, $type_annotations[$type]); + parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $type_annotations[$type]); $this->setCacheBackend($cache_backend, $language_manager, 'aggregator_' . $type . '_plugins'); } diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index a1187a6..980a59f 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -52,9 +52,9 @@ class BlockManager extends DefaultPluginManager { * The translation manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) { - parent::__construct('Plugin/Block', $namespaces, 'Drupal\block\Annotation\Block'); + parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\block\Annotation\Block'); - $this->alterInfo($module_handler, 'block'); + $this->alterInfo('block'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); $this->translationManager = $translation_manager; } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index ffd401b..7cc3b19 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -33,8 +33,8 @@ class CKEditorPluginManager 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('Plugin/CKEditorPlugin', $namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin'); - $this->alterInfo($module_handler, 'ckeditor_plugin_info'); + parent::__construct('Plugin/CKEditorPlugin', $namespaces, $module_handler, 'Drupal\ckeditor\Annotation\CKEditorPlugin'); + $this->alterInfo('ckeditor_plugin_info'); $this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugins'); } diff --git a/core/modules/config_translation/lib/Drupal/config_translation/ConfigMapperManager.php b/core/modules/config_translation/lib/Drupal/config_translation/ConfigMapperManager.php index 7168d26..b39b44d 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/ConfigMapperManager.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/ConfigMapperManager.php @@ -77,7 +77,8 @@ public function __construct(CacheBackendInterface $cache_backend, LanguageManage $this->factory = new ContainerFactory($this); // Let others alter definitions with hook_config_translation_info_alter(). - $this->alterInfo($module_handler, 'config_translation_info'); + $this->moduleHandler = $module_handler; + $this->alterInfo('config_translation_info'); $this->setCacheBackend($cache_backend, $language_manager, 'config_translation_info_plugins'); } diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php index 19b4013..85aa79d 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php @@ -31,8 +31,8 @@ class EditorManager 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('Plugin/Editor', $namespaces, 'Drupal\editor\Annotation\Editor'); - $this->alterInfo($module_handler, 'editor_info'); + parent::__construct('Plugin/Editor', $namespaces, $module_handler, 'Drupal\editor\Annotation\Editor'); + $this->alterInfo('editor_info'); $this->setCacheBackend($cache_backend, $language_manager, 'editor_plugins'); } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php index 8f37384..6ca37c9 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php @@ -33,7 +33,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac // method and don't need the derivative discovery decorator. $this->factory = new ReflectionFactory($this); - $this->alterInfo($module_handler, 'entity_reference_selection'); + $this->moduleHandler = $module_handler; + $this->alterInfo('entity_reference_selection'); $this->setCacheBackend($cache_backend, $language_manager, 'entity_reference_selection_plugins'); } diff --git a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php index 1a1fcc0..2be9e4a 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php +++ b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php @@ -39,8 +39,8 @@ class FilterPluginManager 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('Plugin/Filter', $namespaces, 'Drupal\filter\Annotation\Filter'); - $this->alterInfo($module_handler, 'filter_info'); + parent::__construct('Plugin/Filter', $namespaces, $module_handler, 'Drupal\filter\Annotation\Filter'); + $this->alterInfo('filter_info'); $this->setCacheBackend($cache_backend, $language_manager, 'filter_plugins', array('filter_formats' => TRUE)); } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectManager.php b/core/modules/image/lib/Drupal/image/ImageEffectManager.php index 78ab18b..f025c76 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectManager.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectManager.php @@ -18,12 +18,22 @@ class ImageEffectManager extends DefaultPluginManager { /** - * {@inheritdoc} + * Constructs a new ImageEffectManager. + * + * @param \Traversable $namespaces + * An object that implements \Traversable which contains the root paths + * keyed by the corresponding namespace to look for plugin implementations. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend + * Cache backend instance to use. + * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/ImageEffect', $namespaces, 'Drupal\image\Annotation\ImageEffect'); + parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, 'Drupal\image\Annotation\ImageEffect'); - $this->alterInfo($module_handler, 'image_effect_info'); + $this->alterInfo('image_effect_info'); $this->setCacheBackend($cache_backend, $language_manager, 'image_effect_plugins'); } diff --git a/core/modules/language/lib/Drupal/language/LanguageNegotiationMethodManager.php b/core/modules/language/lib/Drupal/language/LanguageNegotiationMethodManager.php index 1480bd6..681c67c 100644 --- a/core/modules/language/lib/Drupal/language/LanguageNegotiationMethodManager.php +++ b/core/modules/language/lib/Drupal/language/LanguageNegotiationMethodManager.php @@ -28,11 +28,11 @@ 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); + parent::__construct('Plugin/LanguageNegotiation', $namespaces, $module_handler); $this->cacheBackend = $cache_backend; $this->cacheKeyPrefix = 'language_negotiation_plugins'; $this->cacheKey = 'language_negotiation_plugins'; - $this->alterInfo($module_handler, 'language_negotiation_info'); + $this->alterInfo('language_negotiation_info'); } } diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/MigratePluginManager.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigratePluginManager.php index 14692cd..2fa236d 100644 --- a/core/modules/migrate/lib/Drupal/migrate/Plugin/MigratePluginManager.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigratePluginManager.php @@ -39,8 +39,8 @@ class MigratePluginManager extends DefaultPluginManager { * The annotation class name. */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, $annotation = 'Drupal\Component\Annotation\PluginID') { - parent::__construct("Plugin/migrate/$type", $namespaces, $annotation); - $this->alterInfo($module_handler, 'migrate_' . $type . '_info'); + parent::__construct("Plugin/migrate/$type", $namespaces, $module_handler, $annotation); + $this->alterInfo('migrate_' . $type . '_info'); $this->setCacheBackend($cache_backend, $language_manager, 'migrate_plugins_' . $type); } diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php index 6ff5a34..64630ea 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php @@ -31,10 +31,10 @@ class ResourcePluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/rest/resource', $namespaces, 'Drupal\rest\Annotation\RestResource'); + parent::__construct('Plugin/rest/resource', $namespaces, $module_handler, 'Drupal\rest\Annotation\RestResource'); $this->setCacheBackend($cache_backend, $language_manager, 'rest_plugins'); - $this->alterInfo($module_handler, 'rest_resource'); + $this->alterInfo('rest_resource'); } /** diff --git a/core/modules/search/lib/Drupal/search/SearchPluginManager.php b/core/modules/search/lib/Drupal/search/SearchPluginManager.php index 56075d3..4641899 100644 --- a/core/modules/search/lib/Drupal/search/SearchPluginManager.php +++ b/core/modules/search/lib/Drupal/search/SearchPluginManager.php @@ -31,7 +31,7 @@ class SearchPluginManager 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('Plugin/Search', $namespaces, 'Drupal\search\Annotation\SearchPlugin'); + parent::__construct('Plugin/Search', $namespaces, $module_handler, 'Drupal\search\Annotation\SearchPlugin'); $this->setCacheBackend($cache_backend, $language_manager, 'search_plugins'); // @todo Set an alter hook. diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php index 667d954..068fe65 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php @@ -11,6 +11,7 @@ use Drupal\plugin_test\Plugin\TestPluginManager; use Drupal\plugin_test\Plugin\MockBlockManager; use Drupal\plugin_test\Plugin\DefaultsTestPluginManager; +use Drupal\Core\Extension\ModuleHandler; /** * Base class for Plugin API unit tests. @@ -35,8 +36,8 @@ public function setUp() { // - MockBlockManager is used for testing more advanced functionality such // as derivatives and ReflectionFactory. $this->testPluginManager = new TestPluginManager(); - $this->mockBlockManager = new MockBlockManager(); - $this->defaultsTestPluginManager = new DefaultsTestPluginManager(); + $this->mockBlockManager = new MockBlockManager();$module_handler = new ModuleHandler(); + $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler); // The expected plugin definitions within each manager. Several tests assert // that these plugins and their definitions are found and returned by the diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php index 8ca3165..e81c39e 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/DefaultsTestPluginManager.php @@ -9,6 +9,7 @@ use Drupal\Component\Plugin\Discovery\StaticDiscovery; use Drupal\Component\Plugin\Factory\DefaultFactory; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -16,13 +17,20 @@ */ class DefaultsTestPluginManager extends DefaultPluginManager { - public function __construct() { + /** + * Constructs a new DefaultsTestPluginManager instance. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + */ + public function __construct(ModuleHandlerInterface $module_handler) { // Create the object that can be used to return definitions for all the // plugins available for this type. Most real plugin managers use a richer // discovery implementation, but StaticDiscovery lets us add some simple // mock plugins for unit testing. $this->discovery = new StaticDiscovery(); $this->factory = new DefaultFactory($this); + $this->moduleHandler = $module_handler; // Specify default values. $this->defaults = array( diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php index 67dba71..32cf923 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php @@ -31,9 +31,9 @@ class TipPluginManager 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('Plugin/tour/tip', $namespaces, 'Drupal\tour\Annotation\Tip'); + parent::__construct('Plugin/tour/tip', $namespaces, $module_handler, 'Drupal\tour\Annotation\Tip'); - $this->alterInfo($module_handler, 'tour_tips_info'); + $this->alterInfo('tour_tips_info'); $this->setCacheBackend($cache_backend, $language_manager, 'tour_plugins'); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php index b586054..bcf2c85 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php @@ -35,7 +35,7 @@ class ViewsPluginManager extends DefaultPluginManager { */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($type); - parent::__construct("Plugin/views/$type", $namespaces, $plugin_definition_annotation_name); + parent::__construct("Plugin/views/$type", $namespaces, $module_handler, $plugin_definition_annotation_name); $this->defaults += array( 'parent' => 'parent', @@ -43,7 +43,7 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa 'register_theme' => TRUE, ); - $this->alterInfo($module_handler, 'views_plugins_' . $type); + $this->alterInfo('views_plugins_' . $type); $this->setCacheBackend($cache_backend, $language_manager, 'views_' . $type . '_plugins'); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php index 49ab1f8..d6fbff2 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php @@ -7,10 +7,6 @@ namespace Drupal\Tests\Core\Extension; -if (!defined('DRUPAL_ROOT')) { - define('DRUPAL_ROOT', dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))))); -} - use Drupal\Core\Extension\ModuleHandler; use Drupal\Tests\UnitTestCase; use PHPUnit_Framework_Error_Notice; diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php index 6685b9c..9453d9c 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php @@ -379,7 +379,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re $this->account = $account; $this->controllerResolver = $controller_resolver; $this->request = $request; - $this->alterInfo($module_handler, 'menu_local_actions'); + $this->moduleHandler = $module_handler; + $this->alterInfo('menu_local_actions'); $this->setCacheBackend($cache_backend, $language_manager, 'local_action_plugins', array('local_action' => TRUE)); } diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 894a6e1..bd1efc2 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -68,6 +68,31 @@ protected function setUp() { } /** + * Tests the plugin manager with a disabled module. + */ + public function testDefaultPluginManagerWithDisabledModule() { + $definitions = $this->expectedDefinitions; + $definitions['cherry'] = array( + 'id' => 'cherry', + 'label' => 'Cherry', + 'color' => 'red', + 'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry', + 'provider' => 'disabled_module', + ); + + $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); + + $module_handler->expects($this->once()) + ->method('moduleExists') + ->with('disabled_module') + ->will($this->returnValue(FALSE)); + + $plugin_manager = new TestPluginManager($this->namespaces, $definitions, $module_handler, 'test_alter_hook'); + + $this->assertEmpty($plugin_manager->getDefinition('cherry'), 'Plugin information of a disabled module is not available'); + } + + /** * Tests the plugin manager with no cache and altering. */ public function testDefaultPluginManager() { @@ -188,3 +213,7 @@ public function testCacheClearWithTags() { } } + +if (!defined('DRUPAL_ROOT')) { + define('DRUPAL_ROOT', dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))))); +} diff --git a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php index e88008e..a7ea79d 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php +++ b/core/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php @@ -41,8 +41,10 @@ public function __construct(\Traversable $namespaces, array $definitions, Module $this->discovery->setDefinition($key, $definition); } - if ($module_handler && $alter_hook) { - $this->alterInfo($module_handler, $alter_hook); + $this->moduleHandler = $module_handler; + + if ($alter_hook) { + $this->alterInfo($alter_hook); } }