Skip to content
Snippets Groups Projects
Commit 037962ed authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2617152 by Chi, alexpott, dawehner: Single import form needs to handle...

Issue #2617152 by Chi, alexpott, dawehner: Single import form needs to handle invalid YAML correctly and not with an exception

(cherry picked from commit 66320051)
parent 25628e33
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
namespace Drupal\config\Form;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Drupal\Component\Serialization\Yaml;
use Drupal\config\StorageReplaceDataWrapper;
use Drupal\Core\Config\ConfigImporter;
......@@ -281,8 +282,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
return;
}
// Decode the submitted import.
$data = Yaml::decode($form_state->getValue('import'));
try {
// Decode the submitted import.
$data = Yaml::decode($form_state->getValue('import'));
}
catch (InvalidDataTypeException $e) {
$form_state->setErrorByName('import', $this->t('The import failed with the following message: %message', ['%message' => $e->getMessage()]));
}
// Validate for config entities.
if ($form_state->getValue('config_type') !== 'system.simple') {
......
......@@ -37,6 +37,16 @@ public function testImport() {
$uuid = \Drupal::service('uuid');
$this->drupalLogin($this->drupalCreateUser(array('import configuration')));
// Attempt an import with invalid YAML.
$edit = [
'config_type' => 'action',
'import' => '{{{',
];
$this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
$this->assertText('The import failed with the following message: Malformed inline YAML string ({{{) at line 1 (near "{{{")');
$import = <<<EOD
label: First
weight: 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment