diff -u b/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php --- b/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -671,17 +671,15 @@ if (!$this->validated) { // Validate renames. foreach ($this->getUnprocessedConfiguration('rename') as $name) { - $names = explode('::', $name); - $old_name = $names[0]; - $new_name = $names[1]; - $old_entity_type_id = $this->configManager->getEntityTypeIdByName($old_name); - $new_entity_type_id = $this->configManager->getEntityTypeIdByName($new_name); + $names = $this->storageComparer->extractRenameNames($name); + $old_entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']); + $new_entity_type_id = $this->configManager->getEntityTypeIdByName($names['new_name']); if ($old_entity_type_id != $new_entity_type_id) { - $this->logError($this->t('Entity type mismatch on rename. !old_type not equal to !new_type for existing configuration !old_name and staged configuration !new_name.', array('old_type' => $old_entity_type_id, 'new_type' => $new_entity_type_id, 'old_name' => $old_name, 'new_name' => $new_name))); + $this->logError($this->t('Entity type mismatch on rename. !old_type not equal to !new_type for existing configuration !old_name and staged configuration !new_name.', array('old_type' => $old_entity_type_id, 'new_type' => $new_entity_type_id, 'old_name' => $names['old_name'], 'new_name' => $names['new_name']))); } // Has to be a configuration entity. if (!$old_entity_type_id) { - $this->logError($this->t('Rename operation for simple configuration. Existing configuration !old_name and staged configuration !new_name.', array('old_name' => $old_name, 'new_name' => $new_name))); + $this->logError($this->t('Rename operation for simple configuration. Existing configuration !old_name and staged configuration !new_name.', array('old_name' => $names['old_name'], 'new_name' => $names['new_name']))); } } $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this)); @@ -787,9 +785,8 @@ */ protected function checkOp($op, $name) { if ($op == 'rename') { - $names = explode('::', $name); - $new_name = $names[1]; - $target_exists = $this->storageComparer->getTargetStorage()->exists($new_name); + $names = $this->storageComparer->extractRenameNames($name); + $target_exists = $this->storageComparer->getTargetStorage()->exists($names['new_name']); if ($target_exists) { // The rename has already occurred as the result of a secondary // configuration write. Change the operation into an update. This is the @@ -934,17 +931,15 @@ * otherwise. */ protected function importInvokeRename($name) { - $names = explode('::', $name); - $old_name = $names[0]; - $new_name = $names[1]; - $entity_type_id = $this->configManager->getEntityTypeIdByName($old_name); - $old_config = new Config($old_name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); - if ($old_data = $this->storageComparer->getTargetStorage()->read($old_name)) { + $names = $this->storageComparer->extractRenameNames($name); + $entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']); + $old_config = new Config($names['old_name'], $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); + if ($old_data = $this->storageComparer->getTargetStorage()->read($names['old_name'])) { $old_config->initWithData($old_data); } - $data = $this->storageComparer->getSourceStorage()->read($new_name); - $new_config = new Config($new_name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); + $data = $this->storageComparer->getSourceStorage()->read($names['new_name']); + $new_config = new Config($names['new_name'], $this->storageComparer->getTargetStorage(), $this->eventDispatcher, $this->typedConfigManager); if ($data !== FALSE) { $new_config->setData($data); } @@ -953,9 +948,9 @@ // Call to the configuration entity's storage to handle the configuration // change. if (!($entity_storage instanceof ImportableEntityStorageInterface)) { - throw new EntityStorageException(String::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type))); + throw new EntityStorageException(String::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type_id))); } - $entity_storage->importRename($old_name, $new_config, $old_config); + $entity_storage->importRename($names['old_name'], $new_config, $old_config); $this->setProcessedConfiguration('rename', $name); return TRUE; } diff -u b/core/lib/Drupal/Core/Config/StorageComparer.php b/core/lib/Drupal/Core/Config/StorageComparer.php --- b/core/lib/Drupal/Core/Config/StorageComparer.php +++ b/core/lib/Drupal/Core/Config/StorageComparer.php @@ -242,8 +242,8 @@ $this->removeFromChangelist('create', $create_uuids[$data['uuid']]); // Remove from delete list. $this->removeFromChangelist('delete', $id); - // Create rename operation. - $renames[] = $id . '::' . $create_uuids[$data['uuid']]; + // Create the rename name. + $renames[] = $this->createRenameName($id, $create_uuids[$data['uuid']]); } } @@ -270,9 +270,9 @@ * {@inheritdoc} */ public function moveRenameToUpdate($rename) { - $names = explode('::', $rename); + $names = $this->extractRenameNames($rename); $this->removeFromChangelist('rename', $rename); - $this->addChangeList('update', array($names[1]), $this->sourceNames); + $this->addChangeList('update', array($names['new_name']), $this->sourceNames); } /** @@ -318,2 +318,27 @@ + /** + * Creates a rename name from the old and new name. + * + * @param string $old_name + * The old configuration object name. + * @param $new_name + * The new configuration object name. + * + * @return string + * The configuration change name that encodes both the old and the new name. + */ + protected function createRenameName($name1, $name2) { + return $name1 . '::' . $name2; + } + + /** + * {@inheritdoc} + */ + public function extractRenameNames($name) { + $names = explode('::', $name); + return array( + 'old_name' => $names[0], + 'new_name' => $names[1], + ); + } } diff -u b/core/lib/Drupal/Core/Config/StorageComparerInterface.php b/core/lib/Drupal/Core/Config/StorageComparerInterface.php --- b/core/lib/Drupal/Core/Config/StorageComparerInterface.php +++ b/core/lib/Drupal/Core/Config/StorageComparerInterface.php @@ -90,2 +90,16 @@ + /** + * Extracts old and new configuration names from a configuration change name. + * + * @param string $name + * The configuration change name in the format of + * old_config_name::new_config_name. + * + * @return array + * An associative array of configuration names. The array keys are + * 'old_name' and and 'new_name' representing the old and name configuration + * object name during a rename. + */ + public function extractRenameNames($name); + } diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportRenameTest.php @@ -90,10 +90,10 @@ $this->drupalGet('admin/config/development/configuration'); foreach ($expected as $rename) { - $names = explode('::', $rename); - $this->assertText(String::format('!source_name to !target_name', array('!source_name' => $names[0], '!target_name' => $names[1]))); + $names = $this->configImporter()->getStorageComparer()->extractRenameNames($rename); + $this->assertText(String::format('!source_name to !target_name', array('!source_name' => $names['old_name'], '!target_name' => $names['new_name']))); // Test that the diff link is present. - $href = \Drupal::urlGenerator()->getPathFromRoute('config.diff', array('source_name' => $names[0], 'target_name' => $names[1])); + $href = \Drupal::urlGenerator()->getPathFromRoute('config.diff', array('source_name' => $names['old_name'], 'target_name' => $names['new_name'])); $this->assertLinkByHref($href); $hrefs[$rename] = $href; } @@ -101,17 +101,17 @@ // Ensure that the diff works. foreach ($hrefs as $rename => $href) { $this->drupalGet($href); - $names = explode('::', $rename); - $config_entity_type = \Drupal::service('config.manager')->getEntityTypeIdByName($names[0]); + $names = $this->configImporter()->getStorageComparer()->extractRenameNames($rename); + $config_entity_type = \Drupal::service('config.manager')->getEntityTypeIdByName($names['old_name']); $entity_type = \Drupal::entityManager()->getDefinition($config_entity_type); - $old_id = ConfigEntityStorage::getIDFromConfigName($names[0], $entity_type->getConfigPrefix()); - $new_id = ConfigEntityStorage::getIDFromConfigName($names[1], $entity_type->getConfigPrefix()); + $old_id = ConfigEntityStorage::getIDFromConfigName($names['old_name'], $entity_type->getConfigPrefix()); + $new_id = ConfigEntityStorage::getIDFromConfigName($names['new_name'], $entity_type->getConfigPrefix()); $this->assertText('-' . $entity_type->getKey('id') . ': ' . $old_id); $this->assertText('+' . $entity_type->getKey('id') . ': ' . $new_id); } // Run the import. - $this->drupalPostForm(NULL, array(), t('Import all')); + $this->drupalPostForm('admin/config/development/configuration', array(), t('Import all')); $this->assertText(t('There are no configuration changes.')); $this->assertFalse(entity_load('node_type', $active_type), 'Content with old name no longer exists.');