diff --git a/core/core.services.yml b/core/core.services.yml index 868d4ab..788871c 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -513,7 +513,7 @@ services: - { name: event_subscriber } image.toolkit.manager: class: Drupal\system\Plugin\ImageToolkitManager - arguments: ['@container.namespaces', '@cache.cache', '@language_manager'] + arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler'] image.toolkit: class: Drupal\system\Plugin\ImageToolkitInterface factory_method: getDefaultToolkit diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index 14c2a9c..9d206d7 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); - $this->alterInfo($module_handler, 'archiver_info'); + parent::__construct('Plugin/Archiver', $namespaces, $module_handler); + $this->alterInfo('archiver_info'); $this->setCacheBackend($cache_backend, $language_manager, 'archiver_info'); } diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index aa15d56..96681eb 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'); - 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/Entity/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php index 5269769..4ed1a07 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -42,8 +42,8 @@ class FieldTypePluginManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/field/field_type', $namespaces, 'Drupal\Core\Entity\Annotation\FieldType'); - $this->alterInfo($module_handler, 'field_info'); + parent::__construct('Plugin/field/field_type', $namespaces, $module_handler, 'Drupal\Core\Entity\Annotation\FieldType'); + $this->alterInfo('field_info'); $this->setCacheBackend($cache_backend, $language_manager, 'field_types'); // @todo Remove once all core field types have been converted (see diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 39ea454..cada284 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -65,11 +65,11 @@ class LocalActionManager extends DefaultPluginManager { * The language manager. */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { - parent::__construct('Plugin/Menu/LocalAction', $namespaces, 'Drupal\Core\Annotation\Menu\LocalAction'); + parent::__construct('Plugin/Menu/LocalAction', $namespaces, $module_handler, 'Drupal\Core\Annotation\Menu\LocalAction'); $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'); } diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 3ae67fd..05cdb4c 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -101,7 +101,8 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re $this->controllerResolver = $controller_resolver; $this->request = $request; $this->routeProvider = $route_provider; - $this->alterInfo($module_handler, 'local_tasks'); + $this->moduleHandler = $module_handler; + $this->alterInfo('local_tasks'); $this->setCacheBackend($cache, $language_manager, 'local_task', array('local_task' => TRUE)); } diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index d6b0609..c5e0a0f 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -96,15 +96,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; } /** @@ -135,13 +138,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; } @@ -236,6 +236,12 @@ protected function findDefinitions() { if ($this->alterHook) { $this->moduleHandler->alter($this->alterHook, $definitions); } + // If this plugin was provided by a Drupal module, ensure it is enabled. + 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 0e786bd..c102a74 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -46,10 +46,10 @@ class TypedDataManager extends DefaultPluginManager { protected $prototypes = array(); 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'); - 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 91551bc..50ca9da 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'); } diff --git a/core/modules/aggregator/aggregator.services.yml b/core/modules/aggregator/aggregator.services.yml index f622f27..59235ec 100644 --- a/core/modules/aggregator/aggregator.services.yml +++ b/core/modules/aggregator/aggregator.services.yml @@ -1,13 +1,13 @@ 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'] access_check.aggregator.categories: class: Drupal\aggregator\Access\CategoriesAccessCheck arguments: ['@database'] diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php index aca0216..21a3d24 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"); } 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 636d82b..81bc0ef 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_plugin'); } diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php index b9592f5..52e72b8 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'); } 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 2f7edf2..ca5982e 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'); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index f663959..9c46ec2 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -55,10 +55,10 @@ class FormatterPluginManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { - parent::__construct('Plugin/field/formatter', $namespaces, 'Drupal\field\Annotation\FieldFormatter'); + parent::__construct('Plugin/field/formatter', $namespaces, $module_handler, 'Drupal\field\Annotation\FieldFormatter'); $this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types'); - $this->alterInfo($module_handler, 'field_formatter_info'); + $this->alterInfo('field_formatter_info'); $this->fieldTypeManager = $field_type_manager; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 5559e8a..6e9c636 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -54,10 +54,10 @@ class WidgetPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { - parent::__construct('Plugin/field/widget', $namespaces, 'Drupal\field\Annotation\FieldWidget'); + parent::__construct('Plugin/field/widget', $namespaces, $module_handler, 'Drupal\field\Annotation\FieldWidget'); $this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types'); - $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/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 631a151..aec154c 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectManager.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectManager.php @@ -21,9 +21,9 @@ class ImageEffectManager extends DefaultPluginManager { * {@inheritdoc} */ 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'); } 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 0ad6b0f..82fe619 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php @@ -32,10 +32,10 @@ class ResourcePluginManager 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/rest/resource', $namespaces); + parent::__construct('Plugin/rest/resource', $namespaces, $module_handler); $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 ce0e17c..c355807 100644 --- a/core/modules/search/lib/Drupal/search/SearchPluginManager.php +++ b/core/modules/search/lib/Drupal/search/SearchPluginManager.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Session\AccountInterface; @@ -25,10 +26,18 @@ class SearchPluginManager extends DefaultPluginManager { protected $configFactory; /** - * {@inheritdoc} + * Constructs a new SearchPluginManager. + * + * @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\Config\ConfigFactory $config_factory + * The config factory. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct(\Traversable $namespaces, ConfigFactory $config_factory) { - parent::__construct('Plugin/Search', $namespaces, 'Drupal\search\Annotation\SearchPlugin'); + public function __construct(\Traversable $namespaces, ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { + parent::__construct('Plugin/Search', $namespaces, $module_handler, 'Drupal\search\Annotation\SearchPlugin'); $this->configFactory = $config_factory; } diff --git a/core/modules/search/search.services.yml b/core/modules/search/search.services.yml index 22dc7f2..62121c3 100644 --- a/core/modules/search/search.services.yml +++ b/core/modules/search/search.services.yml @@ -1,4 +1,4 @@ services: plugin.manager.search: class: Drupal\search\SearchPluginManager - arguments: ['@container.namespaces', '@config.factory'] + arguments: ['@container.namespaces', '@config.factory', '@module_handler'] diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php index 77e90c1..7611fe8 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php @@ -8,6 +8,7 @@ namespace Drupal\system\Plugin; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; @@ -26,9 +27,11 @@ class ImageToolkitManager 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(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { - parent::__construct('Plugin/ImageToolkit', $namespaces, 'Drupal\system\Annotation\ImageToolkit'); + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { + parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler, 'Drupal\system\Annotation\ImageToolkit'); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php index 5f6c4dc..3c93e0a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php @@ -26,7 +26,7 @@ public static function getInfo() { * available toolkits. */ function testGetAvailableToolkits() { - $manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('cache.cache'), $this->container->get('language_manager')); + $manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('module_handler'), $this->container->get('cache.cache'), $this->container->get('language_manager')); $toolkits = $manager->getAvailableToolkits(); $this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.'); $this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php index a7d097b..5ac6335 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php @@ -47,7 +47,7 @@ function setUp() { parent::setUp(); // Use the image_test.module's test toolkit. - $manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('cache.cache'), $this->container->get('language_manager')); + $manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('module_handler'), $this->container->get('cache.cache'), $this->container->get('language_manager')); $this->toolkit = $manager->createInstance('test'); // Pick a file for testing. 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 917e4e7..10cd4e7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Plugin; +use Drupal\Core\Extension\ModuleHandler; use Drupal\simpletest\UnitTestBase; use Drupal\plugin_test\Plugin\TestPluginManager; use Drupal\plugin_test\Plugin\MockBlockManager; @@ -36,7 +37,8 @@ public function setUp() { // as derivatives and ReflectionFactory. $this->testPluginManager = new TestPluginManager(); $this->mockBlockManager = new MockBlockManager(); - $this->defaultsTestPluginManager = new DefaultsTestPluginManager(); + $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..fb8f897 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 e1b7c23..0ee564d 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'); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php index 13b07fc..3e810d0 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); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php index 45ad0d2..de471ef 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; diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 3e86b66..e93f8df 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -77,6 +77,31 @@ public function testDefaultPluginManager() { } /** + * 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 testDefaultPluginManagerWithAlter() { @@ -186,3 +211,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); } }