You are here

class FeaturesConfigDependencyManager in Features 8.4

Same name and namespace in other branches
  1. 8.3 src/FeaturesConfigDependencyManager.php \Drupal\features\FeaturesConfigDependencyManager

Class FeaturesConfigDependencyManager.

@package Drupal\features

Hierarchy

Expanded class hierarchy of FeaturesConfigDependencyManager

File

src/FeaturesConfigDependencyManager.php, line 13

Namespace

Drupal\features
View source
class FeaturesConfigDependencyManager extends ConfigDependencyManager {
  protected $sorted_graph;

  /**
   * {@inheritdoc}
   */
  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);
    if (!$this->sorted_graph) {

      // 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.
      $this->sorted_graph = $this
        ->getGraph();
      $sorts = $this
        ->prepareMultisort($this->sorted_graph, [
        'weight',
        'name',
      ]);
      array_multisort($sorts['weight'], SORT_DESC, SORT_NUMERIC, $sorts['name'], SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $this->sorted_graph);
    }
    return array_replace(array_intersect_key($this->sorted_graph, $dependencies), $dependencies);
  }

  /**
   * {@inheritdoc}
   */
  public function setData(array $data) {
    parent::setData($data);
    $this->sorted_graph = NULL;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigDependencyManager::$data protected property The config entity data.
ConfigDependencyManager::$graph protected property The directed acyclic graph.
ConfigDependencyManager::createGraphConfigEntityDependencies protected function Creates a graph of config entity dependencies.
ConfigDependencyManager::getGraph protected function Gets the dependency graph of all the config entities.
ConfigDependencyManager::prepareMultisort protected function Extracts data from the graph for use in array_multisort().
ConfigDependencyManager::sortAll public function Sorts the dependencies in order of most dependent last.
ConfigDependencyManager::sortGraph Deprecated public static function Sorts the dependency graph by reverse weight and alphabetically.
ConfigDependencyManager::sortGraphByWeight Deprecated protected static function Sorts the dependency graph by weight and alphabetically.
ConfigDependencyManager::updateData public function Updates one of the lightweight ConfigEntityDependency objects.
FeaturesConfigDependencyManager::$sorted_graph protected property
FeaturesConfigDependencyManager::getDependentEntities public function Gets dependencies. Overrides ConfigDependencyManager::getDependentEntities
FeaturesConfigDependencyManager::setData public function Sets data to calculate dependencies for. Overrides ConfigDependencyManager::setData