public function FeaturesCommands::listPackages in Features 8.4
Same name and namespace in other branches
- 8.3 src/Commands/FeaturesCommands.php \Drupal\features\Commands\FeaturesCommands::listPackages()
Display a list of all generate-able existing features and packages.
If a package name is provided as an argument, then all of the configuration objects assigned to that package will be listed.
@command features:list:packages
@option bundle Use a specific bundle namespace.
@usage drush features:list:packages Display a list of all existing features and packages available to be generated. @usage drush features:list:packages 'example_article' Display a list of all configuration objects assigned to the 'example_article' package.
@field-labels config: Config name: Name machine_name: Machine name status: Status version: Version state: State
@aliases fl,features-list-packages
Parameters
string $package_name: The package to list. Optional; if specified, lists all configuration objects assigned to that package. If no package is specified, lists all of the features.
Return value
\Consolidation\OutputFormatters\StructuredData\RowsOfFields|bool The command output, or FALSE if a requested package was not found.
File
- src/
Commands/ FeaturesCommands.php, line 247
Class
- FeaturesCommands
- Drush commands for Features.
Namespace
Drupal\features\CommandsCode
public function listPackages($package_name = NULL, $options = self::OPTIONS_LIST) {
$assigner = $this
->featuresOptions($options);
$current_bundle = $assigner
->getBundle();
$namespace = $current_bundle
->isDefault() ? FeaturesBundleInterface::DEFAULT_BUNDLE : $current_bundle
->getMachineName();
$manager = $this->manager;
$packages = $manager
->getPackages();
$packages = $manager
->filterPackages($packages, $namespace);
$result = [];
// If no package was specified, list all packages.
if (empty($package_name)) {
foreach ($packages as $package) {
$overrides = $manager
->detectOverrides($package);
$state = $package
->getState();
if (!empty($overrides) && $package
->getStatus() != FeaturesManagerInterface::STATUS_NO_EXPORT) {
$state = FeaturesManagerInterface::STATE_OVERRIDDEN;
}
$packageState = $state != FeaturesManagerInterface::STATE_DEFAULT ? $manager
->stateLabel($state) : '';
$result[$package
->getMachineName()] = [
'name' => $package
->getName(),
'machine_name' => $package
->getMachineName(),
'status' => $manager
->statusLabel($package
->getStatus()),
'version' => $package
->getVersion(),
'state' => $packageState,
];
}
return new RowsOfFields($result);
}
// A valid package was listed.
$package = $this->manager
->findPackage($package_name);
// If no matching package found, return an error.
if (empty($package)) {
$this
->logger()
->warning(dt('Package "@package" not found.', [
'@package' => $package_name,
]));
return FALSE;
}
// This is a valid package, list its configuration.
$config = array_map(function ($name) {
return [
'config' => $name,
];
}, $package
->getConfig());
return new RowsOfFields($config);
}