Commit e6cd1fa5 authored by webchick's avatar webchick

Issue #2388867 by alexpott, xjm, jhodgdon: Notifying user of config changes...

Issue #2388867 by alexpott, xjm, jhodgdon: Notifying user of config changes when config has never been synched makes no sense
parent 1389f057
......@@ -1824,11 +1824,6 @@ function install_finished(&$install_state) {
// Will also trigger indexing of profile-supplied content or feeds.
\Drupal::service('cron')->run();
// Save a snapshot of the initially installed configuration.
$active = \Drupal::service('config.storage');
$snapshot = \Drupal::service('config.storage.snapshot');
\Drupal::service('config.manager')->createSnapshot($active, $snapshot);
if ($install_state['interactive']) {
// Load current user and perform final login tasks.
// This has to be done after drupal_flush_all_caches()
......
......@@ -237,8 +237,8 @@ public function id() {
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage, $update = TRUE) {
// Sort elements by weight before saving.
uasort($this->content, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
ksort($this->content);
ksort($this->hidden);
parent::preSave($storage, $update);
}
......
......@@ -166,33 +166,34 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$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;
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');
}
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',
'#value' => $this->t('Import all'),
);
$source_list = $this->stagingStorage->listAll();
$storage_comparer = new StorageComparer($this->stagingStorage, $this->activeStorage, $this->configManager);
if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
......
......@@ -90,6 +90,11 @@ protected function setUp() {
* Tests a simple site export import case.
*/
public function testExportImport() {
// After installation there is no snapshot and nothing to import.
$this->drupalGet('admin/config/development/configuration');
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->originalSlogan = $this->config('system.site')->get('slogan');
$this->newSlogan = $this->randomString(16);
$this->assertNotEqual($this->newSlogan, $this->originalSlogan);
......@@ -113,6 +118,8 @@ public function testExportImport() {
'field_storage' => $this->fieldStorage,
'bundle' => $this->contentType->id(),
))->save();
// Update the displays so that configuration does not change unexpectedly on
// import.
entity_get_form_display('node', $this->contentType->id(), 'default')
->setComponent($this->fieldName, array(
'type' => 'text_textfield',
......@@ -121,6 +128,12 @@ public function testExportImport() {
entity_get_display('node', $this->contentType->id(), 'full')
->setComponent($this->fieldName)
->save();
entity_get_display('node', $this->contentType->id(), 'default')
->setComponent($this->fieldName)
->save();
entity_get_display('node', $this->contentType->id(), 'teaser')
->removeComponent($this->fieldName)
->save();
$this->drupalGet('node/add/' . $this->contentType->id());
$this->assertFieldByName("{$this->fieldName}[0][value]", '', 'Widget is displayed');
......@@ -154,7 +167,15 @@ public function testExportImport() {
$filename = 'temporary://' . $this->randomMachineName();
file_put_contents($filename, $this->tarball);
$this->drupalPostForm('admin/config/development/configuration/full/import', array('files[import_tarball]' => $filename), 'Upload');
// There is no snapshot yet because an import has never run.
$this->assertNoText(t('Warning message'));
$this->assertNoText(t('There are no configuration changes to import.'));
$this->assertText($this->contentType->label());
$this->drupalPostForm(NULL, array(), 'Import all');
// After importing the snapshot has been updated an there are no warnings.
$this->assertNoText(t('Warning message'));
$this->assertText(t('There are no configuration changes to import.'));
$this->assertEqual($this->config('system.site')->get('slogan'), $this->newSlogan);
......@@ -165,7 +186,15 @@ public function testExportImport() {
->set('slogan', $this->originalSlogan)
->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');
// Remove everything from staging. The warning about differences between the
// active and snapshot should still 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->assertText(t('There are no configuration changes to import.'));
}
/**
......
......@@ -104,6 +104,25 @@ public function testEntityDisplayCRUD() {
$this->assertEqual($new_display->getComponents(), $display->getComponents());
}
/**
* Test sorting of components by name on basic CRUD operations
*/
public function testEntityDisplayCRUDSort() {
$display = entity_create('entity_view_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
$display->setComponent('component_3');
$display->setComponent('component_1');
$display->setComponent('component_2');
$display->removeComponent('name');
$display->save();
$components = array_keys($display->getComponents());
$expected = array ( 0 => 'component_1', 1 => 'component_2', 2 => 'component_3',);
$this->assertIdentical($components, $expected);
}
/**
* Tests entity_get_display().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment