You are here

public function EventSubscriber::onExportTransform in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config/tests/config_transformer_test/src/EventSubscriber.php \Drupal\config_transformer_test\EventSubscriber::onExportTransform()

The storage is transformed for exporting.

In this transformation we ignore the site slogan from the site if the sync storage has it. Just export it again with an additional string so that there will always be something new exported. 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 91

Class

EventSubscriber
Class EventSubscriber.

Namespace

Drupal\config_transformer_test

Code

public function onExportTransform(StorageTransformEvent $event) {
  $sync = $this->sync
    ->read('system.site');

  // Only change something if the sync storage has data.
  if (!empty($sync)) {
    $storage = $event
      ->getStorage();
    $site = $storage
      ->read('system.site');

    // Add "Arrr" to the site slogan. Because pirates!
    // The active slogan will be ignored.
    $site['slogan'] = $sync['slogan'] . ' Arrr';
    $site['mail'] = $this->state
      ->get('config_transform_test_mail', '');
    $storage
      ->write('system.site', $site);
  }
}