diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php index f8ca052f33..adbc6767ed 100644 --- a/core/lib/Drupal/Core/Config/ConfigManager.php +++ b/core/lib/Drupal/Core/Config/ConfigManager.php @@ -292,24 +292,27 @@ public function findConfigEntityDependentsAsEntities($type, array $names, Config * {@inheritdoc} */ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names, $dry_run = TRUE) { - // Determine the current list of dependent configuration entities and set up - // initial values. $dependency_manager = $this->getConfigDependencyManager(); - $original_dependencies = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); + // Store the list of dependencies in three separate variables. This allows // us to determine how the dependency graph changes as entities are fixed by - // calling the onDependencyRemoval() method. The variables are: - // - $current_dependencies is the list of dependencies on $names. This list - // is recalculated when calling an entity's onDependencyRemoval() method - // results in the entity changing. This list is passed to each entity's - // onDependencyRemoval() method as the list of affected entities. - // - $dependencies_to_process is the list of dependencies to process. This list changes - // as entities are processed and either fixed or deleted. - // - $original_dependencies is the list of original dependencies on $names. - // This list never changes. - $dependencies_to_process = $current_dependencies = $original_dependencies; - $affected_uuids = []; + // calling the onDependencyRemoval() method. + + // The list of original dependencies on $names. This list never changes. + $original_dependencies = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); + + // The current list of dependencies on $names. This list is recalculated + // when calling an entity's onDependencyRemoval() method results in the + // entity changing. This list is passed to each entity's + // onDependencyRemoval() method as the list of affected entities. + $current_dependencies = $original_dependencies; + // The list of dependencies to process. This list changes as entities are + // processed and are either fixed or deleted. + $dependencies_to_process = $original_dependencies; + + // Initialize other variables. + $affected_uuids = []; $return = [ 'update' => [], 'delete' => [], @@ -321,17 +324,17 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names // first. For example, this ensures that Menu UI third party dependencies on // node types are fixed before processing the node type's other // dependencies. - while ($dependent = array_pop($dependencies_to_process)) { - /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependent */ + while ($dependency = array_pop($dependencies_to_process)) { + /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependency */ if ($dry_run) { // Clone the entity so any changes do not change any static caches. - $dependent = clone $dependent; + $dependency = clone $dependency; } $fixed = FALSE; - if ($this->callOnDependencyRemoval($dependent, $current_dependencies, $type, $names)) { + if ($this->callOnDependencyRemoval($dependency, $current_dependencies, $type, $names)) { // Recalculate dependencies and update the dependency graph data. - $dependent->calculateDependencies(); - $dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->getDependencies()); + $dependency->calculateDependencies(); + $dependency_manager->updateData($dependency->getConfigDependencyName(), $dependency->getDependencies()); // Based on the updated data rebuild the list of current dependencies. // This will remove entities that are no longer dependent after the // recalculation. @@ -343,33 +346,32 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names return !in_array($current_dependency->uuid(), $affected_uuids); }); // Ensure that the dependency has actually been fixed. It is possible - // that the dependent has multiple dependencies that cause it to be in - // the dependency chain. + // that it has multiple dependencies that cause it to be in the list. $fixed = TRUE; foreach ($dependencies_to_process as $key => $entity) { - if ($entity->uuid() == $dependent->uuid()) { + if ($entity->uuid() == $dependency->uuid()) { $fixed = FALSE; unset($dependencies_to_process[$key]); break; } } if ($fixed) { - $affected_uuids[] = $dependent->uuid(); - $return['update'][] = $dependent; + $affected_uuids[] = $dependency->uuid(); + $return['update'][] = $dependency; } } // If the entity cannot be fixed then it has to be deleted. if (!$fixed) { - $affected_uuids[] = $dependent->uuid(); + $affected_uuids[] = $dependency->uuid(); // Deletes should occur in the order of the least dependent first. For // example, this ensures that fields are removed before field storages. - array_unshift($return['delete'], $dependent); + array_unshift($return['delete'], $dependency); } } // Use the list of affected UUIDs to filter the original list to work out // which configuration entities are unchanged. - $return['unchanged'] = array_filter($original_dependencies, function ($dependent) use ($affected_uuids) { - return !(in_array($dependent->uuid(), $affected_uuids)); + $return['unchanged'] = array_filter($original_dependencies, function ($dependency) use ($affected_uuids) { + return !(in_array($dependency->uuid(), $affected_uuids)); }); return $return;