function EventSubscriber::onImportTransform

Same name in other branches
  1. 9 core/modules/config/tests/config_transformer_test/src/EventSubscriber.php \Drupal\config_transformer_test\EventSubscriber::onImportTransform()
  2. 8.9.x core/modules/config/tests/config_transformer_test/src/EventSubscriber.php \Drupal\config_transformer_test\EventSubscriber::onImportTransform()
  3. 11.x core/modules/config/tests/config_transformer_test/src/EventSubscriber.php \Drupal\config_transformer_test\EventSubscriber::onImportTransform()

The storage is transformed for importing.

In this transformation we ignore the site name from the sync storage and set it always to the currently active site name with an additional string so that there will always be something to import. Do not do this outside of tests.

Parameters

\Drupal\Core\Config\StorageTransformEvent $event: The config storage transform event.

File

core/modules/config/tests/config_transformer_test/src/EventSubscriber.php, line 69

Class

EventSubscriber
Class EventSubscriber.

Namespace

Drupal\config_transformer_test

Code

public function onImportTransform(StorageTransformEvent $event) {
    $storage = $event->getStorage();
    $site = $storage->read('system.site');
    // Only change something if the sync storage has data.
    if (!empty($site)) {
        // Add "Arrr" to the site name. Because pirates!
        // The site name which is in the sync directory will be ignored.
        $current = $this->active
            ->read('system.site');
        $site['name'] = $current['name'] . ' Arrr';
        $storage->write('system.site', $site);
    }
}

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