Skip to content
Snippets Groups Projects
Commit 960e3cf0 authored by codebymikey's avatar codebymikey
Browse files

Issue #3218227: ConfigDeleteInterface::delete should allow ConfigEntity...

Issue #3218227: ConfigDeleteInterface::delete should allow ConfigEntity preDelete hooks to be invoked
parent 1d5e5dfb
No related branches found
No related tags found
1 merge request!8Issue #3218227: ConfigDeleteInterface::delete should allow ConfigEntity preDelete hooks to be invoked
......@@ -17,7 +17,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ConfigReverter implements ConfigRevertInterface, ConfigDeleteInterface {
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
......@@ -186,7 +186,21 @@ class ConfigReverter implements ConfigRevertInterface, ConfigDeleteInterface {
if (!$config) {
return FALSE;
}
$config->delete();
if ($type === 'system.simple') {
$config->delete();
}
else {
// Delete a config entity instance, updating all its dependants.
$definition = $this->entityManager->getDefinition($type);
$id = $config->get($definition->getKey('id'));
$entity_storage = $this->entityManager->getStorage($type);
$entity = $entity_storage->load($id);
if (!$entity) {
return FALSE;
}
$entity->delete();
}
// Trigger an event notifying of this change.
$event = new ConfigRevertEvent($type, $name);
......
......@@ -299,12 +299,15 @@ class ConfigReverterTest extends ConfigUpdateUnitTestBase {
* @covers \Drupal\config_update\ConfigReverter::delete
* @dataProvider deleteProvider
*/
public function testDelete($type, $name, $config_name, $expected) {
public function testDelete($type, $name, $config_name, $expected, $config_before = NULL) {
// Clear dispatch log.
$this->dispatchedEvents = [];
if ($config_name && $config_before) {
$this->configStorage[$config_name] = $config_before;
}
$save_config = $this->configStorage;
// Call the deleteer and test the Boolean result.
// Call the deleter and test the Boolean result.
$result = $this->configReverter->delete($type, $name);
$this->assertEquals($result, $expected);
......@@ -326,7 +329,8 @@ class ConfigReverterTest extends ConfigUpdateUnitTestBase {
*/
public function deleteProvider() {
return [
// Elements: type, name, config name, return value.
// Elements: type, name, config name, return value,
// config to set up before (optional).
[
'system.simple',
'in.extension',
......@@ -338,6 +342,7 @@ class ConfigReverterTest extends ConfigUpdateUnitTestBase {
'one',
'foo.bar.one',
TRUE,
['foo.bar.one' => 'before', 'id' => 'one'],
],
[
'unknown',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment