Issue #2979821 by alexpott, larowlan: \Drupal\config\Form\ConfigSync::processBatch() merges errors incorrectly

merge-requests/1654/head
Lee Rowlands 2018-06-19 06:18:28 +10:00
parent a46c46194d
commit a9ebc01372
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 23 additions and 2 deletions

View File

@ -380,7 +380,7 @@ class ConfigSync extends FormBase {
if (!isset($context['results']['errors'])) {
$context['results']['errors'] = [];
}
$context['results']['errors'] += $errors;
$context['results']['errors'] = array_merge($context['results']['errors'], $errors);
}
}

View File

@ -5,6 +5,8 @@
* Provides configuration import test helpers.
*/
use Drupal\Core\Config\ConfigImporter;
/**
* Implements hook_config_import_steps_alter().
*/
@ -17,9 +19,15 @@ function config_import_test_config_import_steps_alter(&$sync_steps) {
*
* @param array $context
* The batch context.
* @param \Drupal\Core\Config\ConfigImporter $config_importer
* The configuration importer.
*/
function _config_import_test_config_import_steps_alter(&$context) {
function _config_import_test_config_import_steps_alter(&$context, ConfigImporter $config_importer) {
$GLOBALS['hook_config_test']['config_import_steps_alter'] = TRUE;
if (\Drupal::state()->get('config_import_steps_alter.error', FALSE)) {
$context['results']['errors'][] = '_config_import_test_config_import_steps_alter batch error';
$config_importer->logError('_config_import_test_config_import_steps_alter ConfigImporter error');
}
$context['finished'] = 1;
return;
}

View File

@ -518,4 +518,17 @@ class ConfigImportUITest extends BrowserTestBase {
$this->assertText('Unable to install the does_not_exist theme since it does not exist.');
}
/**
* Tests that errors set in the batch and on the ConfigImporter are merged.
*/
public function testBatchErrors() {
$new_site_name = 'Config import test ' . $this->randomString();
$this->prepareSiteNameUpdate($new_site_name);
\Drupal::state()->set('config_import_steps_alter.error', TRUE);
$this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
$this->assertSession()->responseContains('_config_import_test_config_import_steps_alter batch error');
$this->assertSession()->responseContains('_config_import_test_config_import_steps_alter ConfigImporter error');
$this->assertSession()->responseContains('The configuration was imported with errors.');
}
}