You are here

function drush_features_list_packages in Features 8.3

Same name and namespace in other branches
  1. 8.4 drush/features.drush8.inc \drush_features_list_packages()

Drush command callback for features-list-packages.

Parameters

string $package_name: (optional) The package name.

Return value

array|bool

2 calls to drush_features_list_packages()
drush_features_diff in drush/features.drush8.inc
Lists the differences in the package config vs the active store.
drush_features_import in drush/features.drush8.inc
Imports module config into the active store.

File

drush/features.drush8.inc, line 203
Features module drush integration.

Code

function drush_features_list_packages($package_name = '') {
  $assigner = _drush_features_options();
  $current_bundle = $assigner
    ->getBundle();
  $namespace = $current_bundle
    ->isDefault() ? FeaturesBundleInterface::DEFAULT_BUNDLE : $current_bundle
    ->getMachineName();

  /** @var \Drupal\features\FeaturesManagerInterface $manager */
  $manager = \Drupal::service('features.manager');
  $packages = $manager
    ->getPackages();
  $packages = $manager
    ->filterPackages($packages, $namespace);
  $result = [];

  // If no package was specified, list all packages.
  if (empty($package_name)) {
    drush_hide_output_fields([
      'object',
    ]);
    foreach ($packages as $package) {
      $overrides = $manager
        ->detectOverrides($package);
      $state = $package
        ->getState();
      if (!empty($overrides) && $package
        ->getStatus() != FeaturesManagerInterface::STATUS_NO_EXPORT) {
        $state = FeaturesManagerInterface::STATE_OVERRIDDEN;
      }
      $result[$package
        ->getMachineName()] = [
        'name' => $package
          ->getName(),
        'machine_name' => $package
          ->getMachineName(),
        'status' => $manager
          ->statusLabel($package
          ->getStatus()),
        'version' => $package
          ->getVersion(),
        'state' => $state != FeaturesManagerInterface::STATE_DEFAULT ? $manager
          ->stateLabel($state) : '',
      ];
    }
    return $result;
  }
  else {
    foreach ($packages as $package) {
      if ($package
        ->getMachineName() == $package_name) {
        drush_hide_output_fields([
          'machine_name',
          'name',
          'status',
          'version',
          'state',
        ]);
        foreach ($package
          ->getConfig() as $item_name) {
          $result[$item_name] = [
            'object' => $item_name,
          ];
        }
        return $result;
      }
    }
  }

  // If no matching package found, return an error.
  drush_log(dt('Package "@package" not found.', [
    '@package' => $package_name,
  ]), 'warning');
  return FALSE;
}