From 719dfe1683b1563ed0a84ef936fb7fd51c958936 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sat, 29 Mar 2014 16:23:28 +0100 Subject: [PATCH] Issue #2101691 by tim.plunkett, swentel: Allow a custom ID to be specified when using single import for config entity. --- .../config/Form/ConfigSingleImportForm.php | 16 ++++++++++++++++ .../Tests/ConfigSingleImportExportTest.php | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php index b757be6f2a56..129586271e19 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php @@ -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])) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php index 718878bc76e7..46a14d472dc4 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSingleImportExportTest.php @@ -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 -- GitLab