diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index b6c6c7f9aa1b43d8d32eb8f4ba18d10dc4e2aaf7..3be2b32273e520803ebce610db70f4b62423f150 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -996,6 +996,9 @@ protected function importConfig($collection, $op, $name) { $config->delete(); } else { + if ($old_data = $this->storageComparer->getTargetStorage($collection)->read($name)) { + $config->initWithData($old_data); + } $data = $this->storageComparer->getSourceStorage($collection)->read($name); $config->setData($data ? $data : []); $config->save(); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php index 2ab3c547fdbe36fc9fb7f1f5c881cf12e61a74c6..e7f13b762552961e0ecf07b8d79d02009f6ce504 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php @@ -4,6 +4,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Render\FormattableMarkup; +use Drupal\Core\Config\ConfigEvents; use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporterException; use Drupal\KernelTests\KernelTestBase; @@ -25,7 +26,7 @@ class ConfigImporterTest extends KernelTestBase { * * @var array */ - protected static $modules = ['config_test', 'system', 'config_import_test']; + protected static $modules = ['config_test', 'system', 'config_import_test', 'config_events_test']; /** * {@inheritdoc} @@ -899,6 +900,26 @@ public function testUninstallThemeIncrementsCount(): void { $this->assertEquals(0, $this->config($cronName)->get('logging')); } + /** + * Tests config events during config import. + */ + public function testConfigEvents(): void { + $this->installConfig(['config_events_test']); + $this->config('config_events_test.test')->set('key', 'bar')->save(); + $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync')); + $this->config('config_events_test.test')->set('key', 'foo')->save(); + \Drupal::state()->set('config_events_test.event', []); + + // Import the configuration. This results in a save event with the value + // changing from foo to bar. + $this->configImporter()->import(); + $event = \Drupal::state()->get('config_events_test.event', []); + $this->assertSame(ConfigEvents::SAVE, $event['event_name']); + $this->assertSame(['key' => 'bar'], $event['current_config_data']); + $this->assertSame(['key' => 'bar'], $event['raw_config_data']); + $this->assertSame(['key' => 'foo'], $event['original_config_data']); + } + /** * Helper method to test custom config installer steps. *