You are here

public function ConfigDevelAutoExportSubscriber::writeBackConfig in Configuration development 8

write configuration back to files.

Parameters

\Drupal\Core\Config\Config $config: The config object.

array $file_names: The file names to which the configuration should be written.

1 call to ConfigDevelAutoExportSubscriber::writeBackConfig()
ConfigDevelAutoExportSubscriber::autoExportConfig in src/EventSubscriber/ConfigDevelAutoExportSubscriber.php
Automatically export configuration.

File

src/EventSubscriber/ConfigDevelAutoExportSubscriber.php, line 98

Class

ConfigDevelAutoExportSubscriber
ConfigDevelAutoExportSubscriber subscriber for configuration CRUD events.

Namespace

Drupal\config_devel\EventSubscriber

Code

public function writeBackConfig(Config $config, array $file_names) {

  // TODO: use the config_devel.importer_exporter service.
  if ($file_names) {
    $data = $config
      ->get();
    $config_name = $config
      ->getName();
    unset($data['_core']);
    if ($entity_type_id = $this->configManager
      ->getEntityTypeIdByName($config_name)) {
      unset($data['uuid']);
    }

    // Let everyone else have a change to update the exported data.
    $event = new ConfigDevelSaveEvent($file_names, $data);
    $this->eventDispatcher
      ->dispatch(ConfigDevelEvents::SAVE, $event);
    $data = $event
      ->getData();
    $file_names = $event
      ->getFileNames();
    foreach ($file_names as $file_name) {
      try {
        file_put_contents($file_name, (new InstallStorage())
          ->encode($data));
      } catch (DumpException $e) {

        // Do nothing. What could we do?
      }
    }
  }
}