diff --git a/core/includes/module.inc b/core/includes/module.inc index c1d99f2..89f621b 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Graph\Graph; +use Drupal\Core\DrupalKernel; /** * Loads all enabled modules. @@ -475,7 +476,6 @@ function module_enable($module_list, $enable_dependencies = TRUE) { $modules_installed = array(); $modules_enabled = array(); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); $module_config = config('system.module'); $disabled_config = config('system.module.disabled'); foreach ($module_list as $module) { @@ -542,6 +542,10 @@ function module_enable($module_list, $enable_dependencies = TRUE) { entity_info_cache_clear(); module_invoke_all('modules_preenable', array($module)); + // Rebuild the dependency injection container. + $kernel = new DrupalKernel('prod', FALSE, $modules_installed); + $kernel->boot(); + // Enable the module. module_invoke($module, 'enable'); @@ -619,6 +623,9 @@ function module_disable($module_list, $disable_dependents = TRUE) { ->clear("enabled.$module") ->save(); $invoke_modules[] = $module; + + // @todo Probably also rebuild the container somewhere around here. + watchdog('system', '%module module disabled.', array('%module' => $module), WATCHDOG_INFO); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php index 3fa0d1d..de2bb77 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bundle/BundleTest.php @@ -41,4 +41,19 @@ function testBundleRegistration() { $this->drupalGet(''); $this->assertText(t('The bundle_test event subscriber fired!'), 'The bundle_test event subscriber fired'); } + + /** + * Tests module bundle services in the request that enables a module. + */ + function testBundleRegistrationAfterEnableDisable() { + // Test that the bundle is registered after enabling a module. + module_enable(array('bundle_test_dependent')); + $service_exists = in_array('bundle_test_dependent.test_service', drupal_container()->getServiceIds()); + $this->assertTrue($service_exists, 'The bundle_test_dependent.test_service exists on the container.'); + + // Test that the bundle is no longer registered after disabling a module. + module_disable(array('bundle_test_dependent')); + $service_exists = in_array('bundle_test_dependent.test_service', drupal_container()->getServiceIds()); + $this->assertFalse($service_exists, 'The bundle_test_dependent.test_service does not exist on the container.'); + } } diff --git a/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.info b/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.info new file mode 100644 index 0000000..3f7e3ec --- /dev/null +++ b/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.info @@ -0,0 +1,6 @@ +name = "Bundle test dependent" +description = "Support module for bundle testing." +package = Testing +version = VERSION +core = 8.x +hidden = TRUE diff --git a/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.module b/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.module new file mode 100644 index 0000000..eb498dd --- /dev/null +++ b/core/modules/system/tests/modules/bundle_test_dependent/bundle_test_dependent.module @@ -0,0 +1,6 @@ +register('bundle_test_dependent.test_service', 'Drupal\bundle_test_dependent\TestClass'); + } +} diff --git a/core/modules/system/tests/modules/bundle_test_dependent/lib/Drupal/bundle_test_dependent/TestClass.php b/core/modules/system/tests/modules/bundle_test_dependent/lib/Drupal/bundle_test_dependent/TestClass.php new file mode 100644 index 0000000..54b6a27 --- /dev/null +++ b/core/modules/system/tests/modules/bundle_test_dependent/lib/Drupal/bundle_test_dependent/TestClass.php @@ -0,0 +1,15 @@ +