You are here

public function FeaturesManager::assignConfigDependents in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::assignConfigDependents()

For given configuration items, assigns any dependent configuration to the same package.

Parameters

string[] $item_names: Configuration item names.

string $package: Short machine name of package to assign dependent config to. If NULL, use the current package of the parent config items.

Overrides FeaturesManagerInterface::assignConfigDependents

File

src/FeaturesManager.php, line 696

Class

FeaturesManager
The FeaturesManager provides helper functions for building packages.

Namespace

Drupal\features

Code

public function assignConfigDependents(array $item_names = NULL, $package = NULL) {
  $config_collection = $this
    ->getConfigCollection();
  if (empty($item_names)) {
    $item_names = array_keys($config_collection);
  }
  foreach ($item_names as $item_name) {

    // Make sure the extension provided item exists in the active
    // configuration storage.
    if (isset($config_collection[$item_name]) && $config_collection[$item_name]
      ->getPackage()) {
      foreach ($config_collection[$item_name]
        ->getDependents() as $dependent_item_name) {
        if (isset($config_collection[$dependent_item_name]) && (!empty($package) || empty($config_collection[$dependent_item_name]
          ->getPackage()))) {
          try {
            $package_name = !empty($package) ? $package : $config_collection[$item_name]
              ->getPackage();
            $this
              ->assignConfigPackage($package_name, [
              $dependent_item_name,
            ]);
          } catch (\Exception $exception) {
            \Drupal::logger('features')
              ->error($exception
              ->getMessage());
          }
        }
      }
    }
  }
}