You are here

public function ConfigDevelCommands::export in Configuration development 8

Write back configuration to module's config directory.

List which configuration settings you want to export in the module's info file by listing them under 'config_devel', as shown below:

config_devel: install:

  • entity.view_display.node.article.default
  • entity.view_display.node.article.teaser
  • field.instance.node.article.body

optional:

  • field.instance.node.article.tags

@command config:devel-export

@usage drush config-devel-export MODULE_NAME Write back configuration to the specified module, based on .info file. @aliases cde,cd-em,config-devel-export

Parameters

string $extension Machine name of the module, profile or theme to export.:

Throws

\Exception Thrown when the passed in extension

File

src/Commands/ConfigDevelCommands.php, line 128

Class

ConfigDevelCommands
Drush integration for the Configuration Development module.

Namespace

Drupal\config_devel\Commands

Code

public function export($extension) {

  // Determine the type of extension we're dealing with.
  $type = $this
    ->getExtensionType($extension);
  if (!$type) {
    throw new \Exception("Couldn't export configuration. The '{$extension}' extension is not enabled.");
  }

  // Get the config.
  $config = $this
    ->getExtensionConfig($type, $extension);
  if (empty($config)) {
    throw new \Exception(sprintf("Couldn't export configuration. There is no config available for %s.", $extension));
  }

  // Export the required config.
  if (isset($config['install'])) {
    $this
      ->exportConfig($config['install'], $type, $extension, InstallStorage::CONFIG_INSTALL_DIRECTORY);
  }

  // If we have any optional configuration, export that as well.
  if (isset($config['optional'])) {
    $this
      ->exportConfig($config['optional'], $type, $extension, InstallStorage::CONFIG_OPTIONAL_DIRECTORY);
  }
}