You are here

protected function ExportCommand::execute in Commerce Demo 8

Same name and namespace in other branches
  1. 8.2 src/Command/ExportCommand.php \Drupal\commerce_demo\Command\ExportCommand::execute()

File

src/Command/ExportCommand.php, line 92

Class

ExportCommand
Class ExportCommand.

Namespace

Drupal\commerce_demo\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $entity_type_id = $input
    ->getArgument('entity_type');
  $bundle = $input
    ->getArgument('bundle');
  $directory = $input
    ->getOption('directory');
  if ($directory && strpos($directory, -1, 1) != '/') {
    $directory .= '/';
  }

  // Add the bundle to the filename only if the entity type has one.
  $filename = $entity_type_id;
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  if ($entity_type
    ->getKey('bundle')) {
    $filename .= '.' . $bundle;
  }
  $destination = $directory . $filename . '.yml';
  $export = $this->contentExporter
    ->exportAll($entity_type_id, $bundle);
  file_put_contents($destination, Yaml::encode($export));
  $io = new DrupalStyle($input, $output);
  $io
    ->writeln(sprintf($this
    ->trans('commands.commerce_demo.export.messages.success'), $destination));
}