You are here

function _config_import_print_table in Config Importer and Tools 8.0

Same name and namespace in other branches
  1. 8.2 config_import.drush.inc \_config_import_print_table()
  2. 8 config_import.drush.inc \_config_import_print_table()

Output table into command line.

@internal

Parameters

array[] $rows: An array of associative arrays - table rows.

string[] $headers: An associative array of table headers.

2 calls to _config_import_print_table()
drush_config_import_names in ./config_import.drush.inc
Implements drush_COMMAND().
drush_config_import_types in ./config_import.drush.inc
Implements drush_COMMAND().

File

./config_import.drush.inc, line 243
Drush integration.

Code

function _config_import_print_table(array $rows, array $headers) {
  $maxlength = [];

  // Compute the maximum length for every column.
  foreach ($rows as $i => $row) {
    foreach ($row as $key => $value) {
      $maxlength += [
        $key => 0,
      ];
      $length = strlen($value);
      if ($maxlength[$key] < $length) {
        $maxlength[$key] = $length;
      }
    }
  }

  // Forming a separator for header and rows.
  foreach ($maxlength as $key => $value) {
    $maxlength[$key] = implode(array_fill(0, $value, '-'));
  }

  // Append separator as first row.
  array_unshift($rows, $maxlength);
  drush_print(drush_format($rows, [
    'format' => 'table',
    'field-labels' => array_map('dt', $headers),
    'include-field-labels' => TRUE,
  ]));
}