diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index e357a54..957c4e9 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -461,32 +461,25 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie // deletions are already managed. break; } - $dependents = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('config', [$entity->getConfigDependencyName()]); - if (!empty($dependents)) { - // Maybe the dependents can fix themselves. - foreach ($dependents as $dependent) { - // Build up the expected array to pass to onDependencyRemoval. - $dependencies_for_removal = [ - 'config' => [$entity], - 'content' => [], - 'module' => [], - 'theme' => [] - ]; - $dependent->onDependencyRemoval($dependencies_for_removal); - } - // Delete everything can't be fixed. Recalculate the dependencies since - // fixing dependencies can change the dependency chain. - $dependents = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('config', [$entity->getConfigDependencyName()]); - foreach ($dependents as $dependent) { - // Ensure that the dependent still exists. - $storage = \Drupal::entityManager()->getStorage($dependent->getEntityTypeId()); - $dependent = $storage->load($dependent->id()); - if ($dependent) { - $dependent->delete(); - } + + // Fix or remove any dependencies. + while ($dependents = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('config', [$entity->getConfigDependencyName()])) { + $dependent = reset($dependents); + $dependencies_for_removal = [ + 'config' => [$entity], + 'content' => [], + 'module' => [], + 'theme' => [] + ]; + // Because we are only passing in one dependency to the + // onDependencyRemoval method returns TRUE then we assume that the + // dependency has been removed. + if (!$dependent->onDependencyRemoval($dependencies_for_removal)) { + $dependent->delete(); } } } + parent::preDelete($storage, $entities); }