public function ConfigSyncLister::getExtensionChangelist in Configuration Synchronizer 8.2
Same name and namespace in other branches
- 8 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 147
Class
- ConfigSyncLister
- Provides methods related to listing configuration changes.
Namespace
Drupal\config_syncCode
public function getExtensionChangelist($type, $name) {
$update_mode = $this->state
->get('config_sync.update_mode', ConfigSyncListerInterface::DEFAULT_UPDATE_MODE);
// Create a storage with configuration installable from this extension.
$pathname = $this
->drupalGetFilename($type, $name);
$extension = new Extension(\Drupal::root(), $type, $pathname);
$extensions = [
$name => $extension,
];
$this->configCollector
->addInstallableConfig($extensions);
$return = [];
// Return early if the extension has no installable configuration.
// @todo: remove this early return if we introduce support for deletions.
// @see https://www.drupal.org/project/config_sync/issues/2914536
if (empty($this->providerStorage
->listAll())) {
return $return;
}
// For a full reset, compare against the active storage.
if ($update_mode === ConfigSyncListerInterface::UPDATE_MODE_FULL_RESET) {
// Wrap the provider storage.
$normalized_provider_storage = new NormalizedReadOnlyStorage($this->providerStorage, $this->normalizerManager, [
'normalization_mode' => NormalizedReadOnlyStorageInterface::DEFAULT_NORMALIZATION_MODE,
'reference_storage_service' => $this
->getActiveStorages(),
]);
// Set the provider storage as the comparer's source.
$this->activeStorageComparer
->setSourceStorage($normalized_provider_storage);
// Set the context for the active storage.
$this->normalizedActiveStorage
->setContext([
'normalization_mode' => NormalizedReadOnlyStorageInterface::DEFAULT_NORMALIZATION_MODE,
'reference_storage_service' => $this->providerStorage,
]);
$storage_comparer = $this->activeStorageComparer;
}
else {
$snapshot_storage = $this
->getConfigSnapshotStorage(ConfigSyncSnapshotterInterface::CONFIG_SNAPSHOT_SET, $type, $name);
$storage_comparer = $this
->createStorageComparer($this->providerStorage, $snapshot_storage);
}
if ($storage_comparer
->createChangelist()
->hasChanges()) {
foreach ($storage_comparer
->getAllCollectionNames() as $collection) {
$changelist = $storage_comparer
->getChangelist(NULL, $collection);
// We're only concerned with create and update lists.
unset($changelist['delete']);
unset($changelist['rename']);
$changelist = array_filter($changelist);
// Convert the changelist into a format that includes the item label.
foreach ($changelist as $change_type => $item_names) {
foreach ($item_names as $item_name) {
$adjusted_change_type = $change_type;
// Detect cases where we're updating but the item doesn't exist.
// This indicates an item that was installed but later deleted.
$target_exists = $this
->getActiveStorages($collection)
->exists($item_name);
if ($change_type === 'update' && !$target_exists) {
switch ($update_mode) {
// When merging, don't restore an item that was deleted from
// the active storage.
case ConfigSyncListerInterface::UPDATE_MODE_MERGE:
continue 2;
// When resetting, restore a deleted item.
case ConfigSyncListerInterface::UPDATE_MODE_PARTIAL_RESET:
$adjusted_change_type = 'create';
break;
}
}
// 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 = $this->providerStorage
->read($item_name);
$definition = $this->configUpdateLister
->getType($config_type);
$key = $definition
->getKey('label') ?: $definition
->getKey('id');
$label = $config[$key];
}
$return[$collection][$adjusted_change_type][$item_name] = $label;
}
}
}
}
return $return;
}