Commit 719dfe16 authored by alexpott's avatar alexpott

Issue #2101691 by tim.plunkett, swentel: Allow a custom ID to be specified...

Issue #2101691 by tim.plunkett, swentel: Allow a custom ID to be specified when using single import for config entity.
parent 166a3f6a
......@@ -156,6 +156,15 @@ public function buildForm(array $form, array &$form_state) {
'#rows' => 24,
'#required' => TRUE,
);
$form['advanced'] = array(
'#type' => 'details',
'#title' => $this->t('Advanced'),
);
$form['advanced']['custom_entity_id'] = array(
'#title' => $this->t('Custom Entity ID'),
'#type' => 'textfield',
'#description' => $this->t('Specify a custom entity ID. This will override the entity ID in the configuration above.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
......@@ -181,6 +190,13 @@ public function validateForm(array &$form, array &$form_state) {
if ($form_state['values']['config_type'] !== 'system.simple') {
$definition = $this->entityManager->getDefinition($form_state['values']['config_type']);
$id_key = $definition->getKey('id');
// If a custom entity ID is specified, override the value in the
// configuration data being imported.
if (!empty($form_state['values']['custom_entity_id'])) {
$data[$id_key] = $form_state['values']['custom_entity_id'];
}
$entity_storage = $this->entityManager->getStorage($form_state['values']['config_type']);
// If an entity ID was not specified, set an error.
if (!isset($data[$id_key])) {
......
......@@ -73,6 +73,14 @@ public function testImport() {
$this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
$this->assertText(t('An entity with this machine name already exists but the UUID does not match.'));
// Attempt an import with a custom ID.
$edit['custom_entity_id'] = 'custom_id';
$this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
$this->assertRaw(t('Are you sure you want to create new %name @type?', array('%name' => 'custom_id', '@type' => 'test configuration')));
$this->drupalPostForm(NULL, array(), t('Confirm'));
$entity = $storage->load('custom_id');
$this->assertRaw(t('The @entity_type %label was imported.', array('@entity_type' => 'config_test', '%label' => $entity->label())));
// Perform an import with a unique ID and UUID.
$import = <<<EOD
id: second
......
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