diff --git a/core/includes/config.inc b/core/includes/config.inc index 06e0e67..2d4794b 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -4,6 +4,7 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\NullStorage; use Drupal\Core\Config\StorageInterface; +use Drupal\Core\Config\Entity\ConfigStorageController; /** * @file @@ -35,7 +36,7 @@ function config_install_default_config($type, $name) { $manifest_config = config('manifest.' . $entity_info['config_prefix']); $manifest_data = array(); foreach ($source_storage->listAll($entity_info['config_prefix']) as $config_name) { - list(, , $id) = explode('.', $config_name); + $id = ConfigStorageController::idFromConfigName($config_name, $entity_info['config_prefix']); $manifest_data[$id]['name'] = $config_name; } $manifest_config->setData($manifest_data)->save(); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 3dd0b0a..c75205d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -148,6 +148,22 @@ public function getConfigPrefix() { } /** + * Extracts the configuration entity ID from the full configuration name. + * + * @param string $config_name + * The full configuration name to extract the ID from. E.g. + * 'views.view.archive'. + * @param string $config_prefix + * The config prefix of the configuration entity. E.g. 'views.view' + * + * @return string + * The ID of the configuration entity. + */ + public static function idFromConfigName($config_name, $config_prefix) { + return substr($config_name, strlen($config_prefix . '.')); + } + + /** * Builds the query to load the entity. * * This has full revision support. For entities requiring special queries, @@ -269,10 +285,14 @@ public function delete(array $entities) { $config = config($this->getConfigPrefix() . $entity->id()); $config->delete(); - // Remove the entity from the manifest file. - config('manifest.' . $this->entityInfo['config_prefix']) - ->clear($entity->id()) - ->save(); + // Remove the entity from the manifest file. Entity id's can contain a dot + // so we can not use Config::clear() to remove the entity from the + // manifest. + $manifest = config('manifest.' . $this->entityInfo['config_prefix']); + $manifest_data = $manifest->get(); + unset($manifest_data[$entity->id()]); + $manifest->setData($manifest_data); + $manifest->save(); } $this->postDelete($entities); @@ -464,7 +484,7 @@ public function importCreate($name, Config $new_config, Config $old_config) { * A configuration object containing the old configuration data. */ public function importChange($name, Config $new_config, Config $old_config) { - list(, , $id) = explode('.', $name); + $id = substr($name, strlen($this->entityInfo['config_prefix'] . '.')); $entities = $this->load(array($id)); $entity = $entities[$id]; $entity->original = clone $entity; @@ -495,7 +515,7 @@ public function importChange($name, Config $new_config, Config $old_config) { * A configuration object containing the old configuration data. */ public function importDelete($name, Config $new_config, Config $old_config) { - list(, , $id) = explode('.', $name); + $id = substr($name, strlen($this->entityInfo['config_prefix'] . '.')); $entities = $this->load(array($id)); $entity = $entities[$id]; $entity->delete(); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index f19c03d..1eacd3b 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -43,10 +43,10 @@ function testList() { // Get a list of ConfigTest entities and confirm that it contains the // ConfigTest entity provided by the config_test module. - // @see config_test.dynamic.default.yml + // @see config_test.dynamic.test.config.yml $list = $controller->load(); $this->assertEqual(count($list), 1, '1 ConfigTest entity found.'); - $entity = $list['default']; + $entity = $list['test.config']; $this->assertTrue(!empty($entity), '"Default" ConfigTest entity ID found.'); $this->assertTrue($entity instanceof ConfigTest, '"Default" ConfigTest entity is an instance of ConfigTest.'); @@ -55,13 +55,13 @@ function testList() { $expected_operations = array( 'edit' => array ( 'title' => 'Edit', - 'href' => 'admin/structure/config_test/manage/default/edit', + 'href' => 'admin/structure/config_test/manage/test.config/edit', 'options' => $uri['options'], 'weight' => 10, ), 'delete' => array ( 'title' => 'Delete', - 'href' => 'admin/structure/config_test/manage/default/delete', + 'href' => 'admin/structure/config_test/manage/test.config/delete', 'options' => $uri['options'], 'weight' => 100, ), @@ -82,7 +82,7 @@ function testList() { $build_operations = $controller->buildOperations($entity); $expected_items = array( 'label' => 'Default', - 'id' => 'default', + 'id' => 'test.config', 'operations' => array( 'data' => $build_operations, ), @@ -126,7 +126,7 @@ function testListUI() { // the second contains the machine name, and the third contains the // operations list. $this->assertIdentical((string) $elements[0], 'Default'); - $this->assertIdentical((string) $elements[1], 'default'); + $this->assertIdentical((string) $elements[1], 'test.config'); $this->assertTrue($elements[2]->children()->xpath('//ul'), 'Operations list found.'); // Add a new entity using the operations link. @@ -177,7 +177,7 @@ function testListUI() { // Verify that the text of the label and machine name does not appear in // the list (though it may appear elsewhere on the page). $this->assertNoFieldByXpath('//td', 'Default', "No label found for deleted 'Default' entity."); - $this->assertNoFieldByXpath('//td', 'default', "No machine name found for deleted 'Default' entity."); + $this->assertNoFieldByXpath('//td', 'test.config', "No machine name found for deleted 'Default' entity."); // Confirm that the empty text is displayed. $this->assertText('There is no Test configuration yet.'); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php index 32a198a..9436c00 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\config\Tests; use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\Core\Config\Entity\ConfigStorageController; /** * Unit tests for configuration controllers and objects. @@ -38,6 +39,11 @@ public function testStorageControllerMethods() { $expected = $info['config_prefix'] . '.'; $this->assertIdentical($controller->getConfigPrefix(), $expected); + + // Test the static extractID() method. + $expected_id = 'test_id'; + $config_name = $info['config_prefix'] . '.' . $expected_id; + $this->assertIdentical(ConfigStorageController::idFromConfigName($config_name, $info['config_prefix']), $expected_id); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php index 5e62521..97dc002 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -43,11 +43,11 @@ function setUp() { * Tests omission of module APIs for bare configuration operations. */ function testNoImport() { - $dynamic_name = 'config_test.dynamic.default'; + $dynamic_name = 'config_test.dynamic.test.config'; // Verify the default configuration values exist. $config = config($dynamic_name); - $this->assertIdentical($config->get('id'), 'default'); + $this->assertIdentical($config->get('id'), 'test.config'); // Verify that a bare config() does not involve module APIs. $this->assertFalse(isset($GLOBALS['hook_config_test'])); @@ -57,13 +57,13 @@ function testNoImport() { * Tests deletion of configuration during import. */ function testDeleted() { - $dynamic_name = 'config_test.dynamic.default'; + $dynamic_name = 'config_test.dynamic.test.config'; $storage = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); // Verify the default configuration values exist. $config = config($dynamic_name); - $this->assertIdentical($config->get('id'), 'default'); + $this->assertIdentical($config->get('id'), 'test.config'); // Create an empty manifest to delete the configuration object. $staging->write('manifest.config_test.dynamic', array()); @@ -143,7 +143,7 @@ function testNew() { */ function testUpdated() { $name = 'config_test.system'; - $dynamic_name = 'config_test.dynamic.default'; + $dynamic_name = 'config_test.dynamic.test.config'; $storage = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index b549119..ff57878 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -34,7 +34,7 @@ function setUp() { */ function testModuleInstallation() { $default_config = 'config_test.system'; - $default_configuration_entity = 'config_test.dynamic.default'; + $default_configuration_entity = 'config_test.dynamic.test.config'; // Verify that default module config does not exist before installation yet. $config = config($default_config); diff --git a/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml b/core/modules/config/tests/config_test/config/config_test.dynamic.test.config.yml similarity index 72% rename from core/modules/config/tests/config_test/config/config_test.dynamic.default.yml rename to core/modules/config/tests/config_test/config/config_test.dynamic.test.config.yml index fefeed5..14e3767 100644 --- a/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml +++ b/core/modules/config/tests/config_test/config/config_test.dynamic.test.config.yml @@ -1,3 +1,3 @@ -id: default +id: test.config label: Default protected_property: Default