class drush_outputformat_key_value

  1. 8.0.x commands/core/outputformat/key_value.inc drush_outputformat_key_value
  2. 6.x commands/core/outputformat/key_value.inc drush_outputformat_key_value
  3. 7.x commands/core/outputformat/key_value.inc drush_outputformat_key_value
  4. master commands/core/outputformat/key_value.inc drush_outputformat_key_value

Output formatter 'key_value'

Hierarchy

Expanded class hierarchy of drush_outputformat_key_value

Members

File

commands/core/outputformat/key_value.inc, line 58

View source
class drush_outputformat_key_value extends drush_outputformat {
  function format($input, $metadata) {
    if (!is_array($input)) {
      if (isset($metadata['label'])) {
        $input = array(dt($metadata['label']) => $input);
      }
      else {
        return $this->format_error(dt('No label provided.'));
      }
    }
    $kv_metadata = isset($metadata['table-metadata']) ? $metadata['table-metadata'] : array();
    if ((!isset($kv_metadata['key-value-item'])) && (isset($metadata['field-labels']))) {
      $input = drush_select_output_fields($input, $metadata['field-labels'], $metadata['field-mappings']);
    }
    if (isset($metadata['include-field-labels'])) {
      $kv_metadata['include-field-labels'] = $metadata['include-field-labels'];
    }
    $formatted_table = drush_key_value_to_array_table($input, $kv_metadata);
    if ($formatted_table === FALSE) {
      return FALSE;
    }
    return drush_format_table($formatted_table, FALSE, array());
  }
}