Skip to content

Instantly share code, notes, and snippets.

@dmouse
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save dmouse/0b3263acfea7147aa63a to your computer and use it in GitHub Desktop.

Select an option

Save dmouse/0b3263acfea7147aa63a to your computer and use it in GitHub Desktop.
Export configuration in Drupal 8
<?php
use Drupal\Core\Config\FileStorage;
// Empty destination dir and then write all .yml files there.
$source_storage = Drupal::service('config.storage');
$destination_storage = new FileStorage('/tmp/config');
// Export configuration
foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
// Export configuration collections.
foreach (\Drupal::service('config.storage')->getAllCollectionNames() as $collection) {
$source_storage = $source_storage->createCollection($collection);
$destination_storage = $destination_storage->createCollection($collection);
foreach ($source_storage->listAll() as $name) {
$destination_storage->write($name, $source_storage->read($name));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment