Unverified Commit add23701 authored by larowlan's avatar larowlan

Issue #2972003 by alexpott: Verify that the file name matches the ID when installing configuration

parent 346860af
......@@ -315,10 +315,11 @@ protected function createConfiguration($collection, array $config_to_create) {
$entity_storage = $this->configManager
->getEntityManager()
->getStorage($entity_type);
$id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
// It is possible that secondary writes can occur during configuration
// creation. Updates of such configuration are allowed.
if ($this->getActiveStorages($collection)->exists($name)) {
$id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
$entity = $entity_storage->load($id);
$entity = $entity_storage->updateFromStorageRecord($entity, $new_config->get());
}
......@@ -327,6 +328,9 @@ protected function createConfiguration($collection, array $config_to_create) {
}
if ($entity->isInstallable()) {
$entity->trustData()->save();
if ($id !== $entity->id()) {
trigger_error(sprintf('The configuration name "%s" does not match the ID "%s"', $name, $entity->id()), E_USER_WARNING);
}
}
}
else {
......
id: does_not_match
label: Default
weight: 0
protected_property: Default
langcode: en
name: 'Configuration test ID mismatch'
type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:config_test
......@@ -253,6 +253,14 @@ public function testLanguage() {
);
}
/**
* Tests installing configuration where the filename and ID do not match.
*/
public function testIdMisMatch() {
$this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"');
$this->installModules(['config_test_id_mismatch']);
}
/**
* Installs a module.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment