You are here

protected function ConfigDevelCommands::exportConfig in Configuration development 8

Exports a list of configuration entities.

Parameters

array $config_list: An array of configuration entities.

string $type: The type of extension we're exporting, one of 'module', 'profile' or 'theme'.

string $extension: The name of the extension we're exporting.

string $directory: The subdirectory within the extension that we're exporting to. One of \Drupal\Core\Config\InstallStorage\InstallStorage::CONFIG_INSTALL_DIRECTORY or \Drupal\Core\Config\InstallStorage\InstallStorage::CONFIG_OPTIONAL_DIRECTORY.

Throws

\Exception Thrown when the directory to export to is missing and could not be created.

1 call to ConfigDevelCommands::exportConfig()
ConfigDevelCommands::export in src/Commands/ConfigDevelCommands.php
Write back configuration to module's config directory.

File

src/Commands/ConfigDevelCommands.php, line 333

Class

ConfigDevelCommands
Drush integration for the Configuration Development module.

Namespace

Drupal\config_devel\Commands

Code

protected function exportConfig($config_list, $type, $extension, $directory) {
  $config_path = drupal_get_path($type, $extension) . "/{$directory}";

  // Ensure the directory always exists.
  if (!file_exists($config_path) && !$this->fileSystem
    ->mkdir($config_path, NULL, TRUE)) {
    throw new \Exception(sprintf('The %s directory could not be created', $config_path));
  }

  // Use loadMultiple() rather than get(), as get creates a new config object
  // if it doesn't manage to load one, and we don't want that to happen.
  $configs = $this->configFactory
    ->loadMultiple($config_list);
  foreach ($config_list as $name) {
    if (!isset($configs[$name])) {
      $this
        ->logger()
        ->warning("No config found for '{$name}', skipping.");
      continue;
    }
    $file_names = [
      $config_path . '/' . $name . '.yml',
    ];
    $written_files = $this->configImportExport
      ->writeBackConfig($configs[$name], $file_names);
    foreach ($written_files as $written_file_name) {
      $this
        ->output()
        ->writeln('Exported config file ' . $written_file_name . '.');
    }
  }
}