diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php index 0a91758..8dc8db0 100644 --- a/core/modules/config/src/Form/ConfigSync.php +++ b/core/modules/config/src/Form/ConfigSync.php @@ -166,29 +166,6 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - if ($this->snapshotStorage->exists('core.extension')) { - $snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager); - if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) { - $change_list = array(); - foreach ($snapshot_comparer->getAllCollectionNames() as $collection) { - foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) { - if (empty($config_names)) { - continue; - } - foreach ($config_names as $config_name) { - $change_list[] = $config_name; - } - } - } - sort($change_list); - $change_list_render = array( - '#theme' => 'item_list', - '#items' => $change_list, - ); - $change_list_html = drupal_render($change_list_render); - drupal_set_message($this->t('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: !changes', array('!changes' => $change_list_html)), 'warning'); - } - } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', @@ -211,11 +188,35 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['actions']['#access'] = FALSE; return $form; } - else { - // Store the comparer for use in the submit. - $form_state->set('storage_comparer', $storage_comparer); + // A list of changes will be displayed, so check if the user should be + // warned of potential losses to configuration. + if ($this->snapshotStorage->exists('core.extension')) { + $snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager); + if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) { + $change_list = array(); + foreach ($snapshot_comparer->getAllCollectionNames() as $collection) { + foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) { + if (empty($config_names)) { + continue; + } + foreach ($config_names as $config_name) { + $change_list[] = $config_name; + } + } + } + sort($change_list); + $change_list_render = array( + '#theme' => 'item_list', + '#items' => $change_list, + ); + $change_list_html = drupal_render($change_list_render); + drupal_set_message($this->t('The following changes have been made to your active configuration since the last import, and may be lost on the next import: !changes', array('!changes' => $change_list_html)), 'warning'); + } } + // Store the comparer for use in the submit. + $form_state->set('storage_comparer', $storage_comparer); + // Add the AJAX library to the form for dialog support. $form['#attached']['library'][] = 'core/drupal.ajax'; diff --git a/core/modules/config/src/Tests/ConfigExportImportUITest.php b/core/modules/config/src/Tests/ConfigExportImportUITest.php index 3adc1a2..cd94dd8 100644 --- a/core/modules/config/src/Tests/ConfigExportImportUITest.php +++ b/core/modules/config/src/Tests/ConfigExportImportUITest.php @@ -187,14 +187,25 @@ public function testExportImport() { ->save(); $this->drupalGet('admin/config/development/configuration'); $this->assertText(t('Warning message')); - $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site'); + $this->assertText('The following changes have been made to your active configuration since the last import, and may be lost on the next import: system.site'); // Remove everything from staging. The warning about differences between the - // active and snapshot should still exist. + // active and snapshot should no longer exist. \Drupal::service('config.storage.staging')->deleteAll(); $this->drupalGet('admin/config/development/configuration'); - $this->assertText(t('Warning message')); - $this->assertText('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: system.site'); + $this->assertNoText(t('Warning message')); + $this->assertNoText('The following changes have been made to your active configuration since the last import, and may be lost on the next import: system.site'); $this->assertText(t('There are no configuration changes to import.')); + // Write a file to staging. The warning about differences between the + // active and snapshot should now exist. + /** @var \Drupal\Core\Config\StorageInterface $staging */ + $staging = $this->container->get('config.storage.staging'); + $data = $this->config('system.site')->get(); + $data['slogan'] = 'in the face'; + $this->copyConfig($this->container->get('config.storage'), $staging); + $staging->write('system.site', $data); + $this->drupalGet('admin/config/development/configuration'); + $this->assertText(t('Warning message')); + $this->assertText('The following changes have been made to your active configuration since the last import, and may be lost on the next import: system.site'); } /**