function ExcludedModulesEventSubscriber::onConfigTransformImport
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformImport()
- 10 core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformImport()
- 11.x core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformImport()
Transform the storage which is used to import the configuration.
Make sure excluded modules are not uninstalled by adding them and their config to the storage when importing configuration.
Parameters
\Drupal\Core\Config\StorageTransformEvent $event: The transformation event.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ ExcludedModulesEventSubscriber.php, line 74
Class
- ExcludedModulesEventSubscriber
- The event subscriber preventing excluded modules to be exported.
Namespace
Drupal\Core\EventSubscriberCode
public function onConfigTransformImport(StorageTransformEvent $event) {
$storage = $event->getStorage();
if (!$storage->exists('core.extension')) {
// If the core.extension config is not present there is nothing to do.
// This means that probably the storage is empty or non-functional.
return;
}
foreach (array_merge([
StorageInterface::DEFAULT_COLLECTION,
], $this->activeStorage
->getAllCollectionNames()) as $collectionName) {
$collection = $storage->createCollection($collectionName);
$activeCollection = $this->activeStorage
->createCollection($collectionName);
foreach ($this->getDependentConfigNames() as $configName) {
if (!$collection->exists($configName) && $activeCollection->exists($configName)) {
// Make sure the config is not removed if it exists.
$collection->write($configName, $activeCollection->read($configName));
}
}
}
$extension = $storage->read('core.extension');
$existing = $this->activeStorage
->read('core.extension');
$modules = $extension['module'];
foreach ($this->getExcludedModules() as $module) {
if (array_key_exists($module, $existing['module'])) {
// Set the modules weight from the active store.
$modules[$module] = $existing['module'][$module];
}
}
// Sort the extensions.
$extension['module'] = module_config_sort($modules);
// Set the modified extension.
$storage->write('core.extension', $extension);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.