diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index 140a1ad..9209783 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -223,8 +223,8 @@ protected function findDefinitions() { $this->moduleHandler->alter($this->alterHook, $definitions); } // If this plugin was provided by a Drupal module, ensure it is enabled. - foreach ($definitions as $plugin_id => $definition) { - if ($definition['provider'] && !in_array($definition['provider'], array('Core', 'Component')) && !$this->moduleHandler->moduleExists($definition['provider'])) { + 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]); } } 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__))))); +}