diff --git a/core/modules/config/config.api.php b/core/modules/config/config.api.php index d83684c..b1a0ad3 100644 --- a/core/modules/config/config.api.php +++ b/core/modules/config/config.api.php @@ -66,17 +66,17 @@ function hook_config_import_change($name, $new_config, $old_config) { return FALSE; } - // @todo Make this less ugly. - list($entity_type) = explode('.', $name); - $entity_info = entity_get_info($entity_type); - $id = substr($name, strlen($entity_info['config prefix']) + 1); + $id = config_extract_id_from_name($name); $config_test = entity_load('config_test', $id); + // Store the original config, and iterate through each property to store it. $config_test->original = clone $config_test; foreach ($old_config->get() as $property => $value) { $config_test->original->$property = $value; } + // Iterate through each property of the new config, copying it to the + // configurable test object. foreach ($new_config->get() as $property => $value) { $config_test->$property = $value; } diff --git a/core/modules/config/config.module b/core/modules/config/config.module index b3d9bbc..75942a2 100644 --- a/core/modules/config/config.module +++ b/core/modules/config/config.module @@ -1 +1,24 @@ entityInfo['entity class']; $prefix = $this->entityInfo['config prefix'] . '.'; + // Load all of the configurables. if ($ids === NULL) { $names = drupal_container()->get('config.storage')->listAll($prefix); $result = array(); @@ -161,6 +162,7 @@ class ConfigStorageController implements StorageControllerInterface { else { $result = array(); foreach ($ids as $id) { + // Add the prefix to the ID to serve as the configurable name. $config = config($prefix . $id); if (!$config->isNew()) { $result[$id] = new $config_class($config->get(), $this->entityType); diff --git a/core/modules/config/lib/Drupal/config/ConfigurableBase.php b/core/modules/config/lib/Drupal/config/ConfigurableBase.php index a8bc318..ebde0e4 100644 --- a/core/modules/config/lib/Drupal/config/ConfigurableBase.php +++ b/core/modules/config/lib/Drupal/config/ConfigurableBase.php @@ -88,6 +88,8 @@ abstract class ConfigurableBase extends StorableBase implements ConfigurableInte /** * Helper callback for uasort() to sort Configurable entities by weight and label. + * + * @todo Consider moving this to a more genrerically useful place. */ public static function sort($a, $b) { $a_weight = isset($a->weight) ? $a->weight : 0; diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php index 0867812..3e73528 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigConfigurableTest.php @@ -14,6 +14,11 @@ use Drupal\simpletest\WebTestBase; */ class ConfigConfigurableTest extends WebTestBase { + /** + * Modules to enable. + * + * @var array + */ public static $modules = array('config_test'); public static function getInfo() { @@ -28,52 +33,56 @@ class ConfigConfigurableTest extends WebTestBase { * Tests basic CRUD operations through the UI. */ function testCRUD() { + $id = strtolower($this->randomName()); + $label1 = $this->randomName(); + $label2 = $this->randomName(); + $label3 = $this->randomName(); + // Create a configurable entity. - $id = 'thingie'; $edit = array( 'id' => $id, - 'label' => 'Thingie', + 'label' => $label1, ); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->assertResponse(200); - $this->assertText('Thingie'); + $this->assertText($label1); // Update the configurable entity. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id); $edit = array( - 'label' => 'Thongie', + 'label' => $label2, ); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertText('Thongie'); + $this->assertNoText($label1); + $this->assertText($label2); // Delete the configurable entity. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete'); $this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertNoText('Thongie'); + $this->assertNoText($label1); + $this->assertNoText($label2); // Re-create a configurable entity. $edit = array( 'id' => $id, - 'label' => 'Thingie', + 'label' => $label1, ); $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); $this->assertResponse(200); - $this->assertText('Thingie'); + $this->assertText($label1); // Rename the configurable entity's ID/machine name. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id); - $new_id = 'zingie'; $edit = array( - 'id' => $new_id, - 'label' => 'Zingie', + 'id' => strtolower($this->randomName()), + 'label' => $label3, ); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->assertResponse(200); - $this->assertNoText('Thingie'); - $this->assertText('Zingie'); + $this->assertNoText($label1); + $this->assertText($label3); } + } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index e5550d0..a9e6ec7 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -1,5 +1,10 @@ original = clone $config_test; foreach ($old_config->get() as $property => $value) { $config_test->original->$property = $value; } + // Iterate through each property of the new config, copying it to the + // configurable test object. foreach ($new_config->get() as $property => $value) { $config_test->$property = $value; } @@ -58,10 +63,7 @@ function config_test_config_import_delete($name, $new_config, $old_config) { // Set a global value we can check in test code. $GLOBALS['hook_config_import'] = __FUNCTION__; - // @todo Make this less ugly. - list($entity_type) = explode('.', $name); - $entity_info = entity_get_info($entity_type); - $id = substr($name, strlen($entity_info['config prefix']) + 1); + $id = config_extract_id_from_name($name); config_test_delete($id); return TRUE; } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php index 7431e4b..ca3550c 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTest.php @@ -14,10 +14,25 @@ use Drupal\config\ConfigurableBase; */ class ConfigTest extends ConfigurableBase { + /** + * The machine name for the configurable. + * + * @var string + */ public $id; + /** + * The UUID for the configurable. + * + * @var string + */ public $uuid; + /** + * The human-readable name of the configurable. + * + * @var string + */ public $label; /**