diff --git a/core/core.services.yml b/core/core.services.yml index 6f8cce6..13c3907 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -487,7 +487,7 @@ services: - { name: event_subscriber } image.toolkit.manager: class: Drupal\system\Plugin\ImageToolkitManager - arguments: ['@container.namespaces', '@cache.cache', '@language_manager'] + arguments: ['@container.namespaces', '@module_handler', '@cache.cache', '@language_manager'] 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 7f5d630..2807dc4 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -33,13 +33,13 @@ 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'); $annotation_namespaces = array( 'Drupal\Core\Condition\Annotation' => DRUPAL_ROOT . '/core/lib', ); - parent::__construct('Plugin/Condition', $namespaces, $annotation_namespaces, 'Drupal\Core\Condition\Annotation\Condition'); + parent::__construct('Plugin/Condition', $namespaces, $module_handler, $annotation_namespaces, '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 a8c1ef5..be22fc5 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -45,8 +45,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $annotation_namespaces = array( 'Drupal\Core\Entity\Annotation' => DRUPAL_ROOT . '/core/lib', ); - parent::__construct('Plugin/field/field_type', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\FieldType'); - $this->alterInfo($module_handler, 'field_info'); + parent::__construct('Plugin/field/field_type', $namespaces, $module_handler, $annotation_namespaces, '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 f4aab24..55dc5a7 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -59,11 +59,11 @@ class LocalActionManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Menu/LocalAction', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalAction'); + parent::__construct('Plugin/Menu/LocalAction', $namespaces, $module_handler, array(), 'Drupal\Core\Annotation\Menu\LocalAction'); $this->controllerResolver = $controller_resolver; $this->request = $request; - $this->alterInfo($module_handler, 'menu_local_actions'); + $this->alterInfo('menu_local_actions'); } /** diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 00837c5..8692672 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -66,11 +66,11 @@ class LocalTaskManager extends DefaultPluginManager { * The module handler.u */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Menu/LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask'); + parent::__construct('Plugin/Menu/LocalTask', $namespaces, $module_handler, array(), 'Drupal\Core\Annotation\Menu\LocalTask'); $this->controllerResolver = $controller_resolver; $this->request = $request; $this->routeProvider = $route_provider; - $this->alterInfo($module_handler, 'local_tasks'); + $this->alterInfo('local_tasks'); } /** diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index daddaa7..530f10a 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -89,6 +89,8 @@ 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 array $annotation_namespaces * (optional) The namespaces of classes that can be used as annotations. * Defaults to an empty array. @@ -96,11 +98,12 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt * (optional) The name of the annotation that contains the plugin definition. * Defaults to 'Drupal\Component\Annotation\Plugin'. */ - public function __construct($subdir, \Traversable $namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { + public function __construct($subdir, \Traversable $namespaces, ModuleHandlerInterface $module_handler, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->subdir = $subdir; $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $annotation_namespaces, $plugin_definition_annotation_name); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this); + $this->moduleHandler = $module_handler; } /** @@ -127,13 +130,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; } @@ -222,6 +222,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 f217fa5..94b6490 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -46,13 +46,13 @@ 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'); $annotation_namespaces = array( 'Drupal\Core\TypedData\Annotation' => DRUPAL_ROOT . '/core/lib', ); - parent::__construct('Plugin/DataType', $namespaces, $annotation_namespaces, 'Drupal\Core\TypedData\Annotation\DataType'); + parent::__construct('Plugin/DataType', $namespaces, $module_handler, $annotation_namespaces, '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/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index 34daaca..165518f 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -33,8 +33,8 @@ class BlockManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Block', $namespaces); - $this->alterInfo($module_handler, 'block'); + parent::__construct('Plugin/Block', $namespaces, $module_handler); + $this->alterInfo('block'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); } } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index da2bcfd..3acdec6 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -34,8 +34,8 @@ class CKEditorPluginManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $annotation_namespaces = array('Drupal\ckeditor\Annotation' => $namespaces['Drupal\ckeditor']); - parent::__construct('Plugin/CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin'); - $this->alterInfo($module_handler, 'ckeditor_plugin_info'); + parent::__construct('Plugin/CKEditorPlugin', $namespaces, $module_handler, $annotation_namespaces, '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 9adf267..5ba8dc6 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php @@ -32,8 +32,8 @@ class EditorManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $annotation_namespaces = array('Drupal\editor\Annotation' => $namespaces['Drupal\editor']); - parent::__construct('Plugin/Editor', $namespaces, $annotation_namespaces, 'Drupal\editor\Annotation\Editor'); - $this->alterInfo($module_handler, 'editor_info'); + parent::__construct('Plugin/Editor', $namespaces, $module_handler, $annotation_namespaces, '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 11582f2..77fae43 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 @@ -34,7 +34,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 5747fd1..b11b396 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 @@ -46,10 +46,10 @@ class FormatterPluginManager extends DefaultPluginManager { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); - parent::__construct('Plugin/field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter'); + parent::__construct('Plugin/field/formatter', $namespaces, $module_handler, $annotation_namespaces, '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'); } /** 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 f8ea9b7..44b4015 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 @@ -46,10 +46,10 @@ class WidgetPluginManager extends DefaultPluginManager { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); - parent::__construct('Plugin/field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget'); + parent::__construct('Plugin/field/widget', $namespaces, $module_handler, $annotation_namespaces, '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); } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectManager.php b/core/modules/image/lib/Drupal/image/ImageEffectManager.php index 64e251e..06d274e 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectManager.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectManager.php @@ -22,9 +22,9 @@ class ImageEffectManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $annotation_namespaces = array('Drupal\image\Annotation' => $namespaces['Drupal\image']); - parent::__construct('Plugin/ImageEffect', $namespaces, $annotation_namespaces, 'Drupal\image\Annotation\ImageEffect'); + parent::__construct('Plugin/ImageEffect', $namespaces, $module_handler, $annotation_namespaces, '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/system/lib/Drupal/system/Plugin/ImageToolkitManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php index f8e334d..08d8980 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; @@ -22,13 +23,15 @@ class ImageToolkitManager extends DefaultPluginManager { * @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 \Drupal\Core\Cache\CacheBackendInterface $cache_backend * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { - parent::__construct('Plugin/ImageToolkit', $namespaces); + public function __construct(\Traversable $namespaces, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { + parent::__construct('Plugin/ImageToolkit', $namespaces, $module_handler); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php index 624dc79..30c6603 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php @@ -215,7 +215,7 @@ function testManipulations() { ); } - $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')); foreach ($files as $file) { foreach ($operations as $op => $values) { // Load up a fresh image. 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 14a84e9..3e8f98b 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 80b1588..2819f8d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php @@ -31,7 +31,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 c580338..244eaa3 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 fb18d3b..bc7cffc 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php @@ -32,9 +32,9 @@ class TipPluginManager extends DefaultPluginManager { */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { $annotation_namespaces = array('Drupal\tour\Annotation' => $namespaces['Drupal\tour']); - parent::__construct('Plugin/tour/tip', $namespaces, $annotation_namespaces, 'Drupal\tour\Annotation\Tip'); + parent::__construct('Plugin/tour/tip', $namespaces, $module_handler, $annotation_namespaces, '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/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 bd6ba26..d1327ad 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 still available'); + } + + /** * Tests the plugin manager with no cache and altering. */ public function testDefaultPluginManagerWithAlter() { @@ -157,3 +182,7 @@ public function testDefaultPluginManagerWithFilledCache() { } } + +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); } }