From 1d82edfa686e8b576b68bfdd7335f54fb0d60681 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Sun, 24 May 2015 13:59:01 -0500
Subject: [PATCH] Issue #2486475 by Eli-T, alexpott, xjm: Notifying user of
 config changes when config has never been synched still makes no sense

---
 core/modules/config/src/Form/ConfigSync.php   | 53 ++++++++++---------
 .../src/Tests/ConfigExportImportUITest.php    | 19 +++++--
 2 files changed, 42 insertions(+), 30 deletions(-)

diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php
index e0e569116837..c8882b7ac619 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 items in your active configuration have changes since the last import that 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 3adc1a23b3cd..6a63df7c5055 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 items in your active configuration have changes since the last import that 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 items in your active configuration have changes since the last import that 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 items in your active configuration have changes since the last import that may be lost on the next import. system.site');
   }
 
   /**
-- 
GitLab