diff --git a/core/includes/config.inc b/core/includes/config.inc index f2fcd39..390de18 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -1,6 +1,8 @@ delete($name); } @@ -179,6 +187,8 @@ function config_import() { * @param Drupal\Core\Config\StorageInterface $target_storage * The storage to synchronize configuration to. * + * @throws Drupal\Core\Config\ConfigException + * * @todo Add support for other extension types; e.g., themes etc. */ function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { @@ -188,6 +198,10 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou // handle dependencies correctly. foreach (array('delete', 'create', 'change') as $op) { foreach ($config_changes[$op] as $key => $name) { + // Bail out if the configuration object is not namespaced by extension. + if (strpos($name, '.') === FALSE) { + throw new ConfigException(sprintf('Missing namespace in Config name %s', $name)); + } // Extract owner from configuration object name. $module = strtok($name, '.'); // Check whether the module implements hook_config_import() and ask it to diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 2f4d14a..dcc1616 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -238,8 +238,15 @@ class Config { /** * Saves the configuration object. + * + * @throws Drupal\Core\Config\ConfigException */ public function save() { + // All configuration objects need to be namespaced by extension, as it would + // be impossible to maintain them otherwise. + if (strpos($this->name, '.') === FALSE) { + throw new ConfigException(sprintf('Missing namespace in Config name %s', $this->name)); + } $this->sortByKey($this->data); $this->storage->write($this->name, $this->data); $this->isNew = FALSE; diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigNamespaceTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigNamespaceTest.php new file mode 100644 index 0000000..25eb3fd --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigNamespaceTest.php @@ -0,0 +1,58 @@ + 'Namespace', + 'description' => 'Test that an exception is thrown if namespace is missing in Config', + 'group' => 'Configuration', + ); + } + + /** + * Tests CRUD operations. + */ + function testNamespace() { + $name = 'nonamespace'; + $caught_exception = FALSE; + try { + $config = config($name); + $config->save(); + } + catch(ConfigException $e) { + if ($e->getMessage() == "Missing namespace in Config name nonamespace") { + $caught_exception = TRUE; + } + } + $this->assertTrue($caught_exception,'No Namespace exception caught when namespace not specified in config name'); + + $name = 'config.namespace'; + $caught_exception = FALSE; + try { + $config = config($name); + $config->save(); + } + catch(ConfigException $e) { + if ($e->getMessage() == "Missing namespace in Config name nonamespace") { + $caught_exception = TRUE; + } + } + $this->assertFalse($caught_exception,'No Namespace exception not caught when namespace exists in config name'); + } + +}