Issue #2972003 by alexpott: Verify that the file name matches the ID when installing configuration
parent
346860aff3
commit
add2370188
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
id: does_not_match
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
||||
langcode: en
|
|
@ -0,0 +1,7 @@
|
|||
name: 'Configuration test ID mismatch'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:config_test
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue