function ExcludedModulesEventSubscriber::onConfigTransformExport

Same name in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformExport()
  2. 10 core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformExport()
  3. 11.x core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php \Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber::onConfigTransformExport()

Transform the storage which is used to export the configuration.

Make sure excluded modules are not exported by removing all the config which depends on them from the storage that is exported.

Parameters

\Drupal\Core\Config\StorageTransformEvent $event: The transformation event.

File

core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php, line 119

Class

ExcludedModulesEventSubscriber
The event subscriber preventing excluded modules to be exported.

Namespace

Drupal\Core\EventSubscriber

Code

public function onConfigTransformExport(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 some other process has rendered it non-functional already.
        return;
    }
    foreach (array_merge([
        StorageInterface::DEFAULT_COLLECTION,
    ], $storage->getAllCollectionNames()) as $collectionName) {
        $collection = $storage->createCollection($collectionName);
        foreach ($this->getDependentConfigNames() as $configName) {
            $collection->delete($configName);
        }
    }
    $extension = $storage->read('core.extension');
    // Remove all the excluded modules from the extensions list.
    $extension['module'] = array_diff_key($extension['module'], array_flip($this->getExcludedModules()));
    $storage->write('core.extension', $extension);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.