You are here

public function ConfigSyncLister::getExtensionChangelist in Configuration Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/ConfigSyncLister.php \Drupal\config_sync\ConfigSyncLister::getExtensionChangelist()

Returns a change list for a given module or theme.

Parameters

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

string $name: The machine name of the extension.

Return value

array Associative array of configuration changes keyed by the type of change in which values are arrays of configuration item labels keyed by item name.

Overrides ConfigSyncListerInterface::getExtensionChangelist

1 call to ConfigSyncLister::getExtensionChangelist()
ConfigSyncLister::getExtensionChangelists in src/ConfigSyncLister.php
Returns a change list for all installed extensions.

File

src/ConfigSyncLister.php, line 118

Class

ConfigSyncLister
Provides methods related to listing configuration changes.

Namespace

Drupal\config_sync

Code

public function getExtensionChangelist($type, $name) {
  $pathname = $this
    ->drupalGetFilename($type, $name);
  $extension = new Extension(\Drupal::root(), $type, $pathname);
  $extensions = [
    $name => $extension,
  ];

  /* @var \Drupal\config_provider\InMemoryStorage $installable_config */
  $installable_config = $this->configCollector
    ->getInstallableConfig($extensions);

  // Set up a storage comparer.
  $storage_comparer = new StorageComparer($installable_config, $this->snapshotExtensionStorage, $this->configManager);
  $storage_comparer
    ->createChangelist();
  $changelist = $storage_comparer
    ->getChangelist();

  // We're only concerned with create and update lists.
  unset($changelist['delete']);
  $changelist = array_filter($changelist);
  $return = [];

  // Convert the changelist into a format that includes the item label.
  foreach ($changelist as $change_type => $item_names) {
    foreach ($item_names as $item_name) {

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

        // This is simple config.
        $label = $item_name;
      }
      else {
        $config = $installable_config
          ->read($item_name);
        $definition = $this->configUpdateLister
          ->getType($config_type);
        $key = $definition
          ->getKey('label') ?: $definition
          ->getKey('id');
        $label = $config[$key];
      }
      $return[$change_type][$item_name] = $label;
    }
  }
  return $return;
}