function ConfigDependencyManager::getDependentEntities

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php \Drupal\Core\Config\Entity\ConfigDependencyManager::getDependentEntities()
  2. 8.9.x core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php \Drupal\Core\Config\Entity\ConfigDependencyManager::getDependentEntities()
  3. 10 core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php \Drupal\Core\Config\Entity\ConfigDependencyManager::getDependentEntities()

Gets dependencies.

Parameters

string $type: The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.

string $name: The specific name to check. If $type equals 'module' or 'theme' then it should be a module name or theme name. In the case of entity it should be the full configuration object name.

Return value

\Drupal\Core\Config\Entity\ConfigEntityDependency[] An array of config entity dependency objects that are dependent.

File

core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php, line 162

Class

ConfigDependencyManager
Provides a class to discover configuration entity dependencies.

Namespace

Drupal\Core\Config\Entity

Code

public function getDependentEntities($type, $name) {
    $dependent_entities = [];
    $entities_to_check = [];
    if ($type == 'config') {
        $entities_to_check[] = $name;
    }
    else {
        if ($type == 'module' || $type == 'theme' || $type == 'content') {
            $dependent_entities = array_filter($this->data, function (ConfigEntityDependency $entity) use ($type, $name) {
                return $entity->hasDependency($type, $name);
            });
        }
        // If checking content, module, or theme dependencies, discover which
        // entities are dependent on the entities that have a direct dependency.
        foreach ($dependent_entities as $entity) {
            $entities_to_check[] = $entity->getConfigDependencyName();
        }
    }
    $dependencies = array_merge($this->createGraphConfigEntityDependencies($entities_to_check), $dependent_entities);
    // Sort dependencies in the reverse order of the graph. So the least
    // dependent is at the top. For example, this ensures that fields are
    // always after field storages. This is because field storages need to be
    // created before a field.
    $graph = $this->getGraph();
    $sorts = $this->prepareMultisort($graph, [
        'weight',
        'name',
    ]);
    array_multisort($sorts['weight'], SORT_DESC, SORT_NUMERIC, $sorts['name'], SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $graph);
    return array_replace(array_intersect_key($graph, $dependencies), $dependencies);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.