You are here

protected function ConfigSyncInitialize::buildExtensionDetail in Configuration Synchronizer 8

Builds the details of a package.

Parameters

string $type: The type of extension (module or theme).

string $name: The machine name of the extension.

array $changelist: Associative array of configuration changes keyed by the type of change.

Return value

array A render array of a form element.

1 call to ConfigSyncInitialize::buildExtensionDetail()
ConfigSyncInitialize::buildUpdatesListing in src/Form/ConfigSyncInitialize.php
Builds the portion of the form showing a listing of updates.

File

src/Form/ConfigSyncInitialize.php, line 192

Class

ConfigSyncInitialize

Namespace

Drupal\config_sync\Form

Code

protected function buildExtensionDetail($type, $name, $changelist) {
  switch ($type) {
    case 'module':
      $label = $this->moduleHandler
        ->getName($name);
      break;
    case 'theme':
      $label = $this->themeHandler
        ->getName($name);
      break;
  }
  $element['name'] = [
    'data' => [
      '#type' => 'html_tag',
      '#tag' => 'h3',
      '#value' => $label,
    ],
    'class' => [
      'config-sync-extension-name',
    ],
  ];
  $extension_config = [];
  foreach ([
    'create',
    'update',
  ] as $change_type) {
    if (isset($changelist[$change_type])) {
      $extension_config[$change_type] = [];
      foreach ($changelist[$change_type] as $item_name => $item_label) {
        $config_type = $this->configUpdateLister
          ->getTypeNameByConfigName($item_name);
        if (!$config_type) {
          $config_type = 'system_simple';
        }
        if (!isset($extension_config[$change_type][$config_type])) {
          $extension_config[$change_type][$config_type] = [];
        }
        $extension_config[$change_type][$config_type][$item_name] = [
          '#type' => 'html_tag',
          '#tag' => 'span',
          '#value' => $item_label,
          '#attributes' => [
            'title' => $item_name,
            'class' => [
              'config-sync-item',
            ],
          ],
        ];
      }
    }
  }
  $rows = [];
  $change_type_labels = [
    // Match the labels used by core.
    // @see ConfigSync::buildForm().
    'create' => $this
      ->t('New'),
    'update' => $this
      ->t('Changed'),
  ];

  // List config types for order.
  $config_types = $this->configSyncLister
    ->listConfigTypes();
  foreach ($extension_config as $change_type => $change_type_data) {
    $rows[] = [
      [
        'data' => [
          '#type' => 'html_tag',
          '#tag' => 'strong',
          '#value' => $change_type_labels[$change_type],
        ],
        'colspan' => 2,
      ],
    ];
    foreach ($config_types as $config_type => $config_type_label) {
      if (isset($change_type_data[$config_type])) {
        $row = [];
        $row[] = [
          'data' => [
            '#type' => 'html_tag',
            '#tag' => 'span',
            '#value' => $config_type_label,
            '#attributes' => [
              'title' => $config_type,
              'class' => [
                'config-sync-item-label',
              ],
            ],
          ],
        ];
        $row[] = [
          'data' => [
            '#theme' => 'item_list',
            '#items' => $change_type_data[$config_type],
            '#context' => [
              'list_style' => 'comma-list',
            ],
          ],
          'class' => [
            'item',
          ],
        ];
        $rows[] = $row;
      }
    }
  }
  $element['details'] = [
    'data' => [
      '#type' => 'table',
      '#rows' => $rows,
    ],
  ];
  return $element;
}