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

8.6.x
Lee Rowlands 2018-05-14 09:28:54 +10:00
parent 346860aff3
commit add2370188
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
5 changed files with 25 additions and 1 deletions

View File

@ -315,10 +315,11 @@ class ConfigInstaller implements ConfigInstallerInterface {
$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 @@ class ConfigInstaller implements ConfigInstallerInterface {
}
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 {

View File

@ -0,0 +1,5 @@
id: does_not_match
label: Default
weight: 0
protected_property: Default
langcode: en

View File

@ -0,0 +1,7 @@
name: 'Configuration test ID mismatch'
type: module
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:config_test

View File

@ -253,6 +253,14 @@ class ConfigInstallTest extends KernelTestBase {
);
}
/**
* 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.
*