You are here

public function FeaturesCommands::components in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/Commands/FeaturesCommands.php \Drupal\features\Commands\FeaturesCommands::components()

List features components.

@command features:components

@option exported Show only components that have been exported. @option not-exported Show only components that have not been exported. @option bundle Use a specific bundle namespace.

@aliases fc,features-components

@field-labels source: Available sources

Parameters

array $patterns: The components types to list. Omit this argument to list them all.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields|null The command output. May be empty.

File

src/Commands/FeaturesCommands.php, line 539

Class

FeaturesCommands
Drush commands for Features.

Namespace

Drupal\features\Commands

Code

public function components(array $patterns, $options = self::OPTIONS_COMPONENTS) {
  $args = $patterns;
  $this
    ->featuresOptions($options);
  $components = $this
    ->componentList();
  ksort($components);

  // If no args supplied, prompt with a list.
  if (empty($args)) {
    $types = array_keys($components);
    array_unshift($types, 'all');
    $choice = $this
      ->io()
      ->choice('Enter a number to choose which component type to list.', $types);
    if ($choice === FALSE) {
      return NULL;
    }
    $args = $choice == 0 ? [
      '*',
    ] : [
      $types[$choice],
    ];
  }
  $options = [
    'provided by' => TRUE,
  ];
  if ($options['exported']) {
    $options['not exported'] = FALSE;
  }
  elseif ($options['not-exported']) {
    $options['exported'] = FALSE;
  }
  $filtered_components = $this
    ->componentFilter($components, $args, $options);
  if ($filtered_components) {
    return $this
      ->componentPrint($filtered_components);
  }
}