Loading core/lib/Drupal/Core/DrupalKernel.php +13 −0 Original line number Diff line number Diff line Loading @@ -991,6 +991,8 @@ protected function initializeContainer() { $this->containerNeedsDumping = FALSE; $session_started = FALSE; $all_messages = []; $config_is_syncing = FALSE; $source_storage = NULL; if (isset($this->container)) { // Save the id of the currently logged in user. if ($this->container->initialized('current_user')) { Loading @@ -1014,6 +1016,8 @@ protected function initializeContainer() { } $all_messages = $this->container->get('messenger')->all(); $config_is_syncing = $this->container->get('config.installer')->isSyncing(); $source_storage = $this->container->get('config.installer')->getSourceStorage(); } // If the module list hasn't already been set in updateModules and we are Loading Loading @@ -1076,6 +1080,15 @@ protected function initializeContainer() { } } // Restore syncing flag, as this is often set when modules or themes // are installed which triggers a container rebuild. if ($config_is_syncing) { $this->container->get('config.installer')->setSyncing(TRUE); if ($source_storage) { $this->container->get('config.installer')->setSourceStorage($source_storage); } } \Drupal::setContainer($this->container); // Allow other parts of the codebase to react on container initialization in Loading core/lib/Drupal/Core/Extension/ModuleInstaller.php +0 −14 Original line number Diff line number Diff line Loading @@ -714,13 +714,6 @@ function ($definition) { * The list of installed modules. */ protected function updateKernel($module_filenames) { // Save current state of config installer, so it can be restored after the // container is rebuilt. /** @var \Drupal\Core\Config\ConfigInstallerInterface $config_installer */ $config_installer = $this->kernel->getContainer()->get('config.installer'); $sync_status = $config_installer->isSyncing(); $source_storage = $config_installer->getSourceStorage(); if (!empty($module_filenames)) { // This reboots the kernel to register the module's bundle and its // services in the service container. The $module_filenames argument is Loading @@ -738,13 +731,6 @@ protected function updateKernel($module_filenames) { $this->moduleHandler = $container->get('module_handler'); $this->connection = $container->get('database'); $this->updateRegistry = $container->get('update.update_hook_registry'); // Restore state of config installer. if ($sync_status) { $container->get('config.installer') ->setSyncing(TRUE) ->setSourceStorage($source_storage); } } /** Loading core/modules/block/tests/src/Kernel/BlockConfigSyncTest.php +8 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ protected function setUp(): void { parent::setUp(); \Drupal::service(ThemeInstallerInterface::class) ->install(['stark', 'claro']); ->install(['stark']); // Delete all existing blocks. foreach (Block::loadMultiple() as $block) { Loading Loading @@ -71,18 +71,21 @@ public function register(ContainerBuilder $container): void { * should be created. */ #[TestWith([TRUE, NULL])] #[TestWith([FALSE, "claro_test_block"])] #[TestWith([FALSE, "test_theme_test_block"])] public function testNoBlocksCreatedDuringConfigSync(bool $syncing, ?string $expected_block_id): void { \Drupal::service(ConfigInstallerInterface::class) ->setSyncing($syncing); // Invoke the hook that should skip block creation due to config sync. \Drupal::moduleHandler()->invoke('block', 'themes_installed', [['claro']]); // Install a theme that does not provide blocks to ensure that the syncing // flag specifically is verified and blocks are created when syncing is off. \Drupal::service(ThemeInstallerInterface::class) ->install(['test_theme']); // This should hold true if the "current" install profile triggers an // invocation of hook_modules_installed(). \Drupal::moduleHandler()->invoke('block', 'modules_installed', [['testing'], $syncing]); $this->assertSame($expected_block_id, Block::load('claro_test_block')?->id()); $this->assertSame($expected_block_id, Block::load('test_theme_test_block')?->id()); } } Loading
core/lib/Drupal/Core/DrupalKernel.php +13 −0 Original line number Diff line number Diff line Loading @@ -991,6 +991,8 @@ protected function initializeContainer() { $this->containerNeedsDumping = FALSE; $session_started = FALSE; $all_messages = []; $config_is_syncing = FALSE; $source_storage = NULL; if (isset($this->container)) { // Save the id of the currently logged in user. if ($this->container->initialized('current_user')) { Loading @@ -1014,6 +1016,8 @@ protected function initializeContainer() { } $all_messages = $this->container->get('messenger')->all(); $config_is_syncing = $this->container->get('config.installer')->isSyncing(); $source_storage = $this->container->get('config.installer')->getSourceStorage(); } // If the module list hasn't already been set in updateModules and we are Loading Loading @@ -1076,6 +1080,15 @@ protected function initializeContainer() { } } // Restore syncing flag, as this is often set when modules or themes // are installed which triggers a container rebuild. if ($config_is_syncing) { $this->container->get('config.installer')->setSyncing(TRUE); if ($source_storage) { $this->container->get('config.installer')->setSourceStorage($source_storage); } } \Drupal::setContainer($this->container); // Allow other parts of the codebase to react on container initialization in Loading
core/lib/Drupal/Core/Extension/ModuleInstaller.php +0 −14 Original line number Diff line number Diff line Loading @@ -714,13 +714,6 @@ function ($definition) { * The list of installed modules. */ protected function updateKernel($module_filenames) { // Save current state of config installer, so it can be restored after the // container is rebuilt. /** @var \Drupal\Core\Config\ConfigInstallerInterface $config_installer */ $config_installer = $this->kernel->getContainer()->get('config.installer'); $sync_status = $config_installer->isSyncing(); $source_storage = $config_installer->getSourceStorage(); if (!empty($module_filenames)) { // This reboots the kernel to register the module's bundle and its // services in the service container. The $module_filenames argument is Loading @@ -738,13 +731,6 @@ protected function updateKernel($module_filenames) { $this->moduleHandler = $container->get('module_handler'); $this->connection = $container->get('database'); $this->updateRegistry = $container->get('update.update_hook_registry'); // Restore state of config installer. if ($sync_status) { $container->get('config.installer') ->setSyncing(TRUE) ->setSourceStorage($source_storage); } } /** Loading
core/modules/block/tests/src/Kernel/BlockConfigSyncTest.php +8 −5 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ protected function setUp(): void { parent::setUp(); \Drupal::service(ThemeInstallerInterface::class) ->install(['stark', 'claro']); ->install(['stark']); // Delete all existing blocks. foreach (Block::loadMultiple() as $block) { Loading Loading @@ -71,18 +71,21 @@ public function register(ContainerBuilder $container): void { * should be created. */ #[TestWith([TRUE, NULL])] #[TestWith([FALSE, "claro_test_block"])] #[TestWith([FALSE, "test_theme_test_block"])] public function testNoBlocksCreatedDuringConfigSync(bool $syncing, ?string $expected_block_id): void { \Drupal::service(ConfigInstallerInterface::class) ->setSyncing($syncing); // Invoke the hook that should skip block creation due to config sync. \Drupal::moduleHandler()->invoke('block', 'themes_installed', [['claro']]); // Install a theme that does not provide blocks to ensure that the syncing // flag specifically is verified and blocks are created when syncing is off. \Drupal::service(ThemeInstallerInterface::class) ->install(['test_theme']); // This should hold true if the "current" install profile triggers an // invocation of hook_modules_installed(). \Drupal::moduleHandler()->invoke('block', 'modules_installed', [['testing'], $syncing]); $this->assertSame($expected_block_id, Block::load('claro_test_block')?->id()); $this->assertSame($expected_block_id, Block::load('test_theme_test_block')?->id()); } }