You are here

protected function ConfigUpdateController::makeReportTable in Configuration Update Manager 8

Builds a table for the report.

Parameters

string[] $names: List of machine names of config items for the table.

string $storage: Config storage the items can be loaded from, either 'active' or 'extension'.

string[] $actions: Action links to include, one or more of:

  • diff
  • revert
  • export
  • import
  • delete.

Return value

array Render array for the table, not including the #empty and #prefix properties.

1 call to ConfigUpdateController::makeReportTable()
ConfigUpdateController::generateReport in config_update_ui/src/Controller/ConfigUpdateController.php
Generates a report about config updates.

File

config_update_ui/src/Controller/ConfigUpdateController.php, line 482

Class

ConfigUpdateController
Returns responses for Configuration Revert module operations.

Namespace

Drupal\config_update_ui\Controller

Code

protected function makeReportTable(array $names, $storage, array $actions) {
  $build = [];
  $build['#type'] = 'table';
  $build['#attributes'] = [
    'class' => [
      'config-update-report',
    ],
  ];
  $build['#header'] = [
    'name' => [
      'data' => $this
        ->t('Machine name'),
    ],
    'label' => [
      'data' => $this
        ->t('Label (if any)'),
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ],
    'type' => [
      'data' => $this
        ->t('Type'),
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ],
    'provider' => [
      'data' => $this
        ->t('Provider'),
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ],
    'operations' => [
      'data' => $this
        ->t('Operations'),
    ],
  ];
  $build['#rows'] = [];
  foreach ($names as $name) {
    $row = [];
    if ($storage == 'active') {
      $config = $this->configRevert
        ->getFromActive('', $name);
    }
    else {
      $config = $this->configRevert
        ->getFromExtension('', $name);
    }

    // Figure out what type of config it is, and get the ID.
    $entity_type = $this->configList
      ->getTypeNameByConfigName($name);
    if (!$entity_type) {

      // This is simple config.
      $id = $name;
      $label = '';
      $type_label = $this
        ->t('Simple configuration');
      $entity_type = 'system.simple';
    }
    else {
      $definition = $this->configList
        ->getType($entity_type);
      $id_key = $definition
        ->getKey('id');
      $id = $config[$id_key];

      // The label key is not required.
      if ($label_key = $definition
        ->getKey('label')) {
        $label = $config[$label_key];
      }
      else {
        $label = '';
      }
      $type_label = $definition
        ->getLabel();
    }
    $row[] = $name;
    $row[] = $label;
    $row[] = $type_label;
    $provider = $this->configList
      ->getConfigProvider($name);
    $provider_name = '';
    if (!empty($provider)) {
      switch ($provider[0]) {
        case 'profile':
          $provider_name = $this->moduleHandler
            ->getName($provider[1]);
          if ($provider_name) {
            $provider_name = $this
              ->t('@name profile', [
              '@name' => $provider_name,
            ]);
          }
          else {
            $provider_name = '';
          }
          break;
        case 'module':
          $provider_name = $this->moduleHandler
            ->getName($provider[1]);
          if ($provider_name) {
            $provider_name = $this
              ->t('@name module', [
              '@name' => $provider_name,
            ]);
          }
          else {
            $provider_name = '';
          }
          break;
        case 'theme':
          $provider_name = $this->themeHandler
            ->getName($provider[1]);
          if ($provider_name) {
            $provider_name = $this
              ->t('@name theme', [
              '@name' => $provider_name,
            ]);
          }
          else {
            $provider_name = '';
          }
          break;
      }
    }
    $row[] = $provider_name;
    $links = [];
    $routes = [
      'export' => 'config.export_single',
      'import' => 'config_update_ui.import',
      'diff' => 'config_update_ui.diff',
      'revert' => 'config_update_ui.revert',
      'delete' => 'config_update_ui.delete',
    ];
    $titles = [
      'export' => $this
        ->t('Export'),
      'import' => $this
        ->t('Import from source'),
      'diff' => $this
        ->t('Show differences'),
      'revert' => $this
        ->t('Revert to source'),
      'delete' => $this
        ->t('Delete'),
    ];
    foreach ($actions as $action) {
      $links[$action] = [
        'url' => Url::fromRoute($routes[$action], [
          'config_type' => $entity_type,
          'config_name' => $id,
        ]),
        'title' => $titles[$action],
      ];
    }
    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];
    $build['#rows'][] = $row;
  }
  return $build;
}