You are here

public function FeaturesAssignmentNamespace::assignPackages in Features 8.4

Same name and namespace in other branches
  1. 8.3 src/Plugin/FeaturesAssignment/FeaturesAssignmentNamespace.php \Drupal\features\Plugin\FeaturesAssignment\FeaturesAssignmentNamespace::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/FeaturesAssignmentNamespace.php, line 22

Class

FeaturesAssignmentNamespace
Class for assigning configuration to packages based on namespaces.

Namespace

Drupal\features\Plugin\FeaturesAssignment

Code

public function assignPackages($force = FALSE) {
  $packages = $this->featuresManager
    ->getPackages();
  $current_bundle = $this->assigner
    ->getBundle();

  // Build an array of patterns.
  // Keys are short names while values are full machine names.
  // We need full names because existing packages may receive machine names
  // prefixed with a bundle name.
  $patterns = [];
  foreach ($packages as $package) {
    $machine_name = $package
      ->getMachineName();
    $pattern = $current_bundle
      ->getShortName($machine_name);
    $patterns[$pattern] = $machine_name;
  }
  $this->featuresManager
    ->assignConfigByPattern($patterns);
}