public function FeaturesManager::assignInterPackageDependencies in Features 8.3
Same name and namespace in other branches
- 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::assignInterPackageDependencies()
Assigns dependencies between packages based on configuration dependencies.
\Drupal\features\FeaturesBundleInterface::setPackageBundleNames() must be called prior to calling this method.
Parameters
\Drupal\features\FeaturesBundleInterface $bundle: A features bundle.
\Drupal\features\Package[] $packages: An array of packages.
Overrides FeaturesManagerInterface::assignInterPackageDependencies
File
- src/
FeaturesManager.php, line 780
Class
- FeaturesManager
- The FeaturesManager provides helper functions for building packages.
Namespace
Drupal\featuresCode
public function assignInterPackageDependencies(FeaturesBundleInterface $bundle, array &$packages) {
if (!$this->packagesPrefixed) {
throw new \Exception($this
->t('The packages have not yet been prefixed with a bundle name.'));
}
$config_collection = $this
->getConfigCollection();
$module_list = $this->moduleHandler
->getModuleList();
/** @var \Drupal\features\Package[] $packages */
foreach ($packages as $package) {
foreach ($package
->getConfig() as $item_name) {
if (!empty($config_collection[$item_name]
->getData()['dependencies']['config'])) {
foreach ($config_collection[$item_name]
->getData()['dependencies']['config'] as $dependency_name) {
if (isset($config_collection[$dependency_name]) && $config_collection[$dependency_name]
->getSubdirectory() === InstallStorage::CONFIG_INSTALL_DIRECTORY) {
// If the required item is assigned to one of the packages, add
// a dependency on that package.
$dependency_set = FALSE;
if ($dependency_package = $config_collection[$dependency_name]
->getPackage()) {
$package_name = $bundle
->getFullName($dependency_package);
if ($package_name && array_key_exists($package_name, $packages) && isset($module_list[$package_name])) {
$package
->appendDependency($package_name);
$dependency_set = TRUE;
}
}
// Otherwise, if the dependency is provided by an existing
// feature, add a dependency on that feature.
if (!$dependency_set && ($extension_name = $config_collection[$dependency_name]
->getProvider())) {
// No extension should depend on the install profile.
$package_name = $bundle
->getFullName($package
->getMachineName());
if ($extension_name != $package_name && $extension_name != $this
->drupalGetProfile() && isset($module_list[$extension_name])) {
$package
->appendDependency($extension_name);
}
}
}
}
}
}
}
// Unset the $package pass by reference.
unset($package);
}