public function FeaturesManager::listPackageDirectories in Features 8.3
Same name and namespace in other branches
- 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::listPackageDirectories()
Lists directories in which packages are present.
This method scans to find package modules whether or not they are currently active (installed). As well as the directories that are usually scanned for modules and profiles, a profile directory for the current profile is scanned if it exists. For example, if the value for $bundle->getProfileName() is 'example', a directory profiles/example will be scanned if it exists. Therefore, when regenerating package modules, existing ones from a prior export will be recognized.
Parameters
string[] $machine_names: Package machine names to return directories for. If omitted, return all directories.
\Drupal\features\FeaturesBundleInterface $bundle: Optional bundle to use to add profile directories to the scan.
Return value
array Array of package directories keyed by package machine name.
Overrides FeaturesManagerInterface::listPackageDirectories
File
- src/
FeaturesManager.php, line 432
Class
- FeaturesManager
- The FeaturesManager provides helper functions for building packages.
Namespace
Drupal\featuresCode
public function listPackageDirectories(array $machine_names = [], FeaturesBundleInterface $bundle = NULL) {
if (empty($machine_names)) {
$machine_names = array_keys($this
->getPackages());
}
// If the bundle is a profile, then add the profile's machine name.
if (isset($bundle) && $bundle
->isProfile() && !in_array($bundle
->getProfileName(), $machine_names)) {
$machine_names[] = $bundle
->getProfileName();
}
// If we are checking the default bundle, return all features.
if (isset($bundle) && $bundle
->isDefault()) {
$bundle = NULL;
}
$modules = $this
->getFeaturesModules($bundle);
// Filter to include only the requested packages.
$modules = array_filter($modules, function ($module) use ($bundle, $machine_names) {
return in_array($module
->getName(), $machine_names);
});
$directories = [];
foreach ($modules as $module) {
$directories[$module
->getName()] = $module
->getPath();
}
return $directories;
}