public ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval($type, array $names, $dry_run = TRUE)
Lists which config entities to update and delete on removal of a dependency.
Parameters
string $type: The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.
array $names: The specific names to check. If $type equals 'module' or 'theme' then it should be a list of module names or theme names. In the case of 'config' or 'content' it should be a list of configuration dependency names.
bool $dry_run: If set to FALSE the entities returned in the list of updates will be modified. In order to make the changes the caller needs to save them. If set to TRUE the entities returned will not be modified.
Return value
array An array with the keys: 'update', 'delete' and 'unchanged'. The value of each is a list of configuration entities that need to have that action applied when the supplied dependencies are removed. Updates need to be processed before deletes. The order of the deletes is significant and must be processed in the returned order.
Overrides ConfigManagerInterface::getConfigEntitiesToChangeOnDependencyRemoval
File
- core/lib/Drupal/Core/Config/ConfigManager.php, line 294
Class
- ConfigManager
- The ConfigManager provides helper functions for the configuration system.
Namespace
Drupal\Core\Config
Code
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(); $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); $original_dependencies = $dependents; $delete_uuids = $update_uuids = []; $return = [ 'update' => [], 'delete' => [], 'unchanged' => [], ]; // Try to fix any dependencies and find out what will happen to the // dependency graph. Entities are processed in the order of most dependent // 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($dependents)) { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependent */ if ($dry_run) { // Clone the entity so any changes do not change any static caches. $dependent = clone $dependent; } $fixed = FALSE; if ($this->callOnDependencyRemoval($dependent, $original_dependencies, $type, $names)) { // Recalculate dependencies and update the dependency graph data. $dependent->calculateDependencies(); $dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->getDependencies()); // Based on the updated data rebuild the list of dependents. This will // remove entities that are no longer dependent after the recalculation. $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager); // Remove any entities that we've already marked for deletion. $dependents = array_filter($dependents, function($dependent) use ($delete_uuids) { return !in_array($dependent->uuid(), $delete_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. $fixed = TRUE; foreach ($dependents as $key => $entity) { if ($entity->uuid() == $dependent->uuid()) { $fixed = FALSE; unset($dependents[$key]); break; } } if ($fixed) { $return['update'][] = $dependent; $update_uuids[] = $dependent->uuid(); } } // If the entity cannot be fixed then it has to be deleted. if (!$fixed) { $delete_uuids[] = $dependent->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); } } // Use the lists of UUIDs to filter the original list to work out which // configuration entities are unchanged. $return['unchanged'] = array_filter($original_dependencies, function($dependent) use ($delete_uuids, $update_uuids) { return !(in_array($dependent->uuid(), $delete_uuids) || in_array($dependent->uuid(), $update_uuids)); }); return $return; }
Please login to continue.