You are here

public function FeaturesAssignmentForwardDependency::assignPackages in Features 8.4

Same name and namespace in other branches
  1. 8.3 src/Plugin/FeaturesAssignment/FeaturesAssignmentForwardDependency.php \Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentForwardDependency::assignPackages()

Performs package assignment.

Parameters

bool $force: (optional) If TRUE, assign config regardless of restrictions such as it being already assigned to a package.

Overrides FeaturesAssignmentMethodInterface::assignPackages

File

src/Plugin/FeaturesAssignment/FeaturesAssignmentForwardDependency.php, line 23

Class

FeaturesAssignmentForwardDependency
Class for assigning configuration to packages based on forward dependencies.

Namespace

Drupal\features\Plugin\FeaturesAssignment

Code

public function assignPackages($force = FALSE) {
  $config_collection = $this->featuresManager
    ->getConfigCollection();
  $ordered = $this
    ->dependencyOrder($config_collection);
  foreach ($ordered as $name) {
    $item = $config_collection[$name];
    if ($item
      ->getPackage()) {

      // Already has a package, not our business.
      continue;
    }

    // Find packages of dependent items.
    $dependent_packages = [];
    foreach ($item
      ->getDependents() as $dependent) {
      if (isset($config_collection[$dependent])) {
        if ($package = $config_collection[$dependent]
          ->getPackage()) {
          $dependent_packages[$package] = $package;
        }
      }
    }

    // If zero or multiple packages, we don't know what to do.
    if (count($dependent_packages) == 1) {
      $package = key($dependent_packages);
      $this->featuresManager
        ->assignConfigPackage($package, [
        $name,
      ]);
    }
  }
}