function drush_outputformat_key_value::format

8.0.x key_value.inc drush_outputformat_key_value::format($input, $metadata)
6.x key_value.inc drush_outputformat_key_value::format($input, $metadata)
7.x key_value.inc drush_outputformat_key_value::format($input, $metadata)
master key_value.inc drush_outputformat_key_value::format($input, $metadata)

Overrides drush_outputformat::format

File

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

Class

drush_outputformat_key_value
Output formatter 'key_value'

Code

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());
}