diff -u b/core/includes/module.inc b/core/includes/module.inc --- b/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. @@ -478,9 +479,9 @@ $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'); + $system_list = system_list(); foreach ($module_list as $module) { // Only process modules that are not already enabled. $enabled = $module_config->get("enabled.$module") !== NULL; @@ -544,6 +545,11 @@ // Allow modules to react prior to the enabling of a module. entity_info_cache_clear(); module_invoke_all('modules_preenable', array($module)); + // Rebuild the container. + $system_list['module_enabled'][$module] = ''; + $system_list['module_enabled_hash'] = hash('sha256', implode(',', array_keys($system_list['module_enabled']))); + $kernel = new DrupalKernel('prod', FALSE, $system_list, FALSE); + $kernel->boot(); // Enable the module. module_invoke($module, 'enable'); only in patch2: unchanged: --- 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,12 @@ function testBundleRegistration() { $this->drupalGet(''); $this->assertText(t('The bundle_test event subscriber fired!'), 'The bundle_test event subscriber fired'); } + + /** + * Test that services provided by module bundles are available in the same request that the module is enabled. + */ + function testBundleRegistrationAfterEnable() { + $this->drupalGet('bundle_test_dependent'); + $this->assertText('Drupal\bundle_test_dependent::test()'); + } } only in patch2: unchanged: --- a/core/modules/system/tests/modules/bundle_test/bundle_test.module +++ b/core/modules/system/tests/modules/bundle_test/bundle_test.module @@ -1 +1,25 @@ 'Bundle test dependent callback', + 'page callback' => 'bundle_test_dependent_callback', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +/** + * Enables the bundle_test_dependent module and invokes one of its services. + */ +function bundle_test_dependent_callback() { + module_enable(array('bundle_test_dependent')); + return drupal_container()->get('bundle_test_dependent.test_service')->test(); +}