function ConfigExportCommand::renderTable

Prints the change list of a storage comparer as a table.

Parameters

\Drupal\Core\Config\StorageComparer $comparer: The comparer holding the change list to render.

\Symfony\Component\Console\Style\SymfonyStyle $io: The input and output style.

File

core/lib/Drupal/Core/Config/Command/ConfigExportCommand.php, line 98

Class

ConfigExportCommand
Export configuration.

Namespace

Drupal\Core\Config\Command

Code

protected function renderTable(StorageComparer $comparer, SymfonyStyle $io) : void {
  $translations = [
    'delete' => (string) $this->t('Delete'),
    'update' => (string) $this->t('Update'),
    'create' => (string) $this->t('Create'),
    'rename' => (string) $this->t('Rename'),
  ];
  $styles = [
    'delete' => 'fg=white;bg=red',
    'update' => 'fg=black;bg=yellow',
    'create' => 'fg=white;bg=green',
    'rename' => 'fg=black;bg=cyan',
  ];
  $header = [
    (string) $this->t('Collection'),
    (string) $this->t('Config'),
    (string) $this->t('Operation'),
  ];
  $rows = [];
  foreach ($comparer->getAllCollectionNames() as $collection) {
    foreach ($comparer->getChangelist(NULL, $collection) as $op => $names) {
      foreach ($names as $name) {
        $rows[] = [
          $collection,
          $op !== 'rename' ? $name : str_replace('::', ' -> ', $name),
          \sprintf('<%s>%s</>', $styles[$op], $translations[$op]),
        ];
      }
    }
  }
  $io->table($header, $rows);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.