ConfigSyncLister.php in Configuration Synchronizer 8
File
src/ConfigSyncLister.php
View source
<?php
namespace Drupal\config_sync;
use Drupal\config_provider\Plugin\ConfigCollectorInterface;
use Drupal\config_update\ConfigListInterface as ConfigUpdateListerInterface;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\Extension;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class ConfigSyncLister implements ConfigSyncListerInterface {
use StringTranslationTrait;
protected $configCollector;
protected $configUpdateLister;
protected $activeStorage;
protected $snapshotExtensionStorage;
protected $configManager;
protected $configTypes = [];
public function __construct(ConfigCollectorInterface $config_collector, ConfigUpdateListerInterface $config_update_lister, StorageInterface $active_storage, StorageInterface $snapshot_extension_storage, ConfigManagerInterface $config_manager) {
$this->configCollector = $config_collector;
$this->configUpdateLister = $config_update_lister;
$this->activeStorage = $active_storage;
$this->snapshotExtensionStorage = $snapshot_extension_storage;
$this->configManager = $config_manager;
}
public function getExtensionChangelists(array $extension_names = []) {
$changelist = [];
if (empty($extension_names)) {
$installed_extensions = $this->activeStorage
->read('core.extension');
foreach (array(
'module',
'theme',
) as $type) {
if (!empty($installed_extensions[$type])) {
$extension_names[$type] = array_keys($installed_extensions[$type]);
}
}
}
foreach ($extension_names as $type => $names) {
foreach ($names as $name) {
if ($extension_changelist = $this
->getExtensionChangelist($type, $name)) {
if (!isset($changelist[$type])) {
$changelist[$type] = [];
}
$changelist[$type][$name] = $extension_changelist;
}
}
}
return $changelist;
}
public function getExtensionChangelist($type, $name) {
$pathname = $this
->drupalGetFilename($type, $name);
$extension = new Extension(\Drupal::root(), $type, $pathname);
$extensions = [
$name => $extension,
];
$installable_config = $this->configCollector
->getInstallableConfig($extensions);
$storage_comparer = new StorageComparer($installable_config, $this->snapshotExtensionStorage, $this->configManager);
$storage_comparer
->createChangelist();
$changelist = $storage_comparer
->getChangelist();
unset($changelist['delete']);
$changelist = array_filter($changelist);
$return = [];
foreach ($changelist as $change_type => $item_names) {
foreach ($item_names as $item_name) {
$config_type = $this->configUpdateLister
->getTypeNameByConfigName($item_name);
if (!$config_type) {
$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;
}
public function listConfigTypes() {
if (empty($this->configTypes)) {
$definitions = $this->configUpdateLister
->listTypes();
$config_types = array_map(function (EntityTypeInterface $definition) {
return $definition
->getLabel();
}, $definitions);
$config_types['system_simple'] = $this
->t('Simple configuration');
uasort($config_types, 'strnatcasecmp');
$this->configTypes = $config_types;
}
return $this->configTypes;
}
protected function drupalGetFilename($type, $name, $filename = NULL) {
return drupal_get_filename($type, $name, $filename);
}
}