You are here

function _drush_features_component_list in Features 6

Same name and namespace in other branches
  1. 8.4 drush/features.drush8.inc \_drush_features_component_list()
  2. 8.3 drush/features.drush8.inc \_drush_features_component_list()
  3. 7.2 features.drush.inc \_drush_features_component_list()
  4. 7 features.drush.inc \_drush_features_component_list()

List all possible features components.

Parameters

$arg: A specific component to search for. Used as variable-get command.

$source: Restrict component lookup to the specified source.

$render: Determine whether the results will be immediately printed to the screen or returned for further processing.

2 calls to _drush_features_component_list()
drush_features_add in ./features.drush.inc
Add a component to a features module.
_drush_features_component_find in ./features.drush.inc
Help the user select a Features component if one can be recommended.

File

./features.drush.inc, line 313
Features module drush integration.

Code

function _drush_features_component_list($arg = NULL, $source = NULL, $render = TRUE) {
  static $items;
  $index = empty($source) ? 'all' : $source;
  $index .= ':';
  $index .= empty($arg) ? 'all' : $arg;
  if (empty($items[$index])) {
    $components = features_get_components(TRUE);
    if ($arg) {
      $heading = dt('Components similar to "!arg"', array(
        '!arg' => $arg,
      ));
    }
    else {
      $heading = dt('Available components');
    }
    if ($source) {
      $heading .= ' ' . dt('in category "!source"', array(
        '!source' => $source,
      ));
      if (array_key_exists($source, $components)) {
        $components = array(
          $source => $components[$source],
        );
      }
      else {
        return FALSE;
      }
    }
    $rows = array(
      array(
        $heading,
      ),
    );
    foreach ($components as $component => $info) {
      if ($options = features_invoke($component, 'features_export_options')) {
        foreach ($options as $key => $value) {
          if (empty($arg) || strpos($key, $arg) !== FALSE) {
            $rows[$component . ':' . $key] = array(
              $component . ':' . $key,
            );
          }
        }
      }
    }
    $items[$index] = $rows;
  }
  if ($render) {
    drush_print_table(array_values($items[$index]), TRUE);
    return array_keys($items[$index]);
  }
  return array_slice(array_keys($items[$index]), 1);
}