You are here

protected function ConfigUpdateController::generateReport in Configuration Update Manager 8

Generates a report about config updates.

Parameters

string $report_type: Type of report to generate: 'type', 'module', 'theme', or 'profile'.

string $value: Machine name of a configuration type, module, or theme to generate the report for. Ignored for profile, since that uses the active profile.

Return value

array Render array for the updates report. Empty if invalid or missing report type or value.

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

File

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

Class

ConfigUpdateController
Returns responses for Configuration Revert module operations.

Namespace

Drupal\config_update_ui\Controller

Code

protected function generateReport($report_type, $value) {

  // Figure out what to name the report, and incidentally, validate that
  // $value exists for this type of report.
  switch ($report_type) {
    case 'type':
      if ($value == 'system.all') {
        $label = $this
          ->t('All configuration');
      }
      elseif ($value == 'system.simple') {
        $label = $this
          ->t('Simple configuration');
      }
      else {
        $definition = $this->configList
          ->getType($value);
        if (!$definition) {
          return NULL;
        }
        $label = $this
          ->t('@name configuration', [
          '@name' => $definition
            ->getLabel(),
        ]);
      }
      break;
    case 'module':
      $list = $this->moduleHandler
        ->getModuleList();
      if (!isset($list[$value])) {
        return NULL;
      }
      $label = $this
        ->t('@name module', [
        '@name' => $this->moduleHandler
          ->getName($value),
      ]);
      break;
    case 'theme':
      $list = $this->themeHandler
        ->listInfo();
      if (!isset($list[$value])) {
        return NULL;
      }
      $label = $this
        ->t('@name theme', [
        '@name' => $this->themeHandler
          ->getName($value),
      ]);
      break;
    case 'profile':
      $profile = $this
        ->getProfileName();
      $label = $this
        ->t('@name profile', [
        '@name' => $this->moduleHandler
          ->getName($profile),
      ]);
      break;
    default:
      return NULL;
  }

  // List the active and extension-provided config.
  list($active_list, $install_list, $optional_list) = $this->configList
    ->listConfig($report_type, $value);

  // Build the report.
  $build = [];
  $build['#title'] = $this
    ->t('Configuration updates report for @label', [
    '@label' => $label,
  ]);
  $build['report_header'] = [
    '#markup' => '<h3>' . $this
      ->t('Updates report') . '</h3>',
  ];

  // List items missing from site.
  $removed = array_diff($install_list, $active_list);
  $build['removed'] = [
    '#caption' => $this
      ->t('Missing configuration items'),
    '#empty' => $this
      ->t('None: all provided configuration items are in your active configuration.'),
  ] + $this
    ->makeReportTable($removed, 'extension', [
    'import',
  ]);

  // List optional items that are not installed.
  $inactive = array_diff($optional_list, $active_list);
  $build['inactive'] = [
    '#caption' => $this
      ->t('Inactive optional items'),
    '#empty' => $this
      ->t('None: all optional configuration items are in your active configuration.'),
  ] + $this
    ->makeReportTable($inactive, 'extension', [
    'import',
  ]);

  // List items added to site, which only makes sense in the report for a
  // config type.
  $added = array_diff($active_list, $install_list, $optional_list);
  if ($report_type == 'type') {
    $build['added'] = [
      '#caption' => $this
        ->t('Added configuration items'),
      '#empty' => $this
        ->t('None: all active configuration items of this type were provided by modules, themes, or install profile.'),
    ] + $this
      ->makeReportTable($added, 'active', [
      'export',
      'delete',
    ]);
  }

  // For differences, we need to go through the array of config in both
  // and see if each config item is the same or not.
  $both = array_diff($active_list, $added);
  $different = [];
  foreach ($both as $name) {
    if (!$this->configDiff
      ->same($this->configRevert
      ->getFromExtension('', $name), $this->configRevert
      ->getFromActive('', $name))) {
      $different[] = $name;
    }
  }
  $build['different'] = [
    '#caption' => $this
      ->t('Changed configuration items'),
    '#empty' => $this
      ->t('None: no active configuration items differ from their current provided versions.'),
  ] + $this
    ->makeReportTable($different, 'active', [
    'diff',
    'export',
    'revert',
  ]);
  return $build;
}