You are here

protected function ExportCommand::execute in Commerce Demo 8.2

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

File

src/Command/ExportCommand.php, line 91

Class

ExportCommand
Provides a command for exporting content entities.

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');

  // 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));
}