function ConfigExportCommand::__invoke

Export the configuration.

Parameters

\Symfony\Component\Console\Style\SymfonyStyle $io: The symfony style.

bool $yes: The command option to skip the confirmation question.

Return value

int The command result.

File

core/lib/Drupal/Core/Config/Command/ConfigExportCommand.php, line 53

Class

ConfigExportCommand
Export configuration.

Namespace

Drupal\Core\Config\Command

Code

public function __invoke(SymfonyStyle $io, #[Option(description: 'Answer the confirmation question with yes.', shortcut: 'y')] bool $yes = FALSE) : int {
  // Resolve the sync storage here rather than in the constructor: the
  // factory throws when no sync directory is configured, and a throwing
  // constructor would break `dr list` for every command.
  try {
    $sync = $this->syncFactory
      ->get();
  } catch (ConfigDirectoryNotDefinedException $e) {
    $io->error($e->getMessage());
    return self::FAILURE;
  }
  $comparer = new StorageComparer($this->export, $sync);
  $comparer->createChangelist();
  if (!$comparer->hasChanges()) {
    $io->success((string) $this->t('The active configuration to export matches the configuration in the sync directory.'));
    return self::SUCCESS;
  }
  $this->renderTable($comparer, $io);
  if (!$yes && !$io->confirm((string) $this->t('Do you want to export the configuration?'))) {
    throw new UserAbortException('Cancelled');
  }
  self::replaceStorageContents($this->export, $sync);
  $io->success((string) $this->t('Configuration successfully exported'));
  return self::SUCCESS;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.