You are here

public static function ContentSyncCommands::contentChangesTable in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Commands/ContentSyncCommands.php \Drupal\content_sync\Commands\ContentSyncCommands::contentChangesTable()

Builds a table of content changes.

Parameters

array $content_changes: An array of changes keyed by collection.

\Symfony\Component\Console\Output\OutputInterface $output: The output.

bool $use_color: If it should use color.

Return value

\Symfony\Component\Console\Helper\Table A Symfony table object.

2 calls to ContentSyncCommands::contentChangesTable()
ContentSyncCommands::export in src/Commands/ContentSyncCommands.php
Export Drupal content to a directory.
ContentSyncCommands::import in src/Commands/ContentSyncCommands.php
Import content from a content directory.

File

src/Commands/ContentSyncCommands.php, line 406

Class

ContentSyncCommands
A Drush commandfile.

Namespace

Drupal\content_sync\Commands

Code

public static function contentChangesTable(array $content_changes, OutputInterface $output, $use_color = TRUE) {
  $rows = [];
  foreach ($content_changes as $collection => $changes) {
    if (is_array($changes)) {
      foreach ($changes as $change => $contents) {
        switch ($change) {
          case 'delete':
            $colour = '<fg=white;bg=red>';
            break;
          case 'update':
            $colour = '<fg=black;bg=yellow>';
            break;
          case 'create':
            $colour = '<fg=white;bg=green>';
            break;
          default:
            $colour = "<fg=black;bg=cyan>";
            break;
        }
        if ($use_color) {
          $prefix = $colour;
          $suffix = '</>';
        }
        else {
          $prefix = $suffix = '';
        }
        foreach ($contents as $content) {
          $rows[] = [
            $collection,
            $content,
            $prefix . ucfirst($change) . $suffix,
          ];
        }
      }
    }
  }
  $table = new Table($output);
  $table
    ->setHeaders([
    'Collection',
    'Content Name',
    'Operation',
  ]);
  $table
    ->addRows($rows);
  return $table;
}