You are here

public function DefaultContentDeployCommands::contentDeployExportWithReferences in Default Content Deploy 8

Exports a single entity with references.

@command default-content-deploy:export-with-references

@option entity_id The ID of the entity to export. @option bundle Write out the exported bundle of entity @option skip_entities The ID of the entity to skip. @option force-update Deletes configurations files that are not used on the site. @option folder Path to the export folder. @usage drush dcder node Export all nodes with references @usage drush dcder node --folder='../content' Export all nodes with references from the specified folder. @usage drush dcder node --bundle=page Export all nodes with references with bundle page @usage drush dcder node --bundle=page,article --entity_id=2,3,4 Export all nodes with references with bundle page or article plus nodes with entitiy id 2, 3 and 4. @usage drush dcder node --bundle=page,article --skip_entities=5,7 Export all nodes with references with bundle page or article and skip nodes with entity id 5 and 7. @usage drush dcder node --skip_entities=5,7 Export all nodes and skip nodes with references with entity id 5 and 7. @aliases dcder,default-content-deploy-export-with-references

Parameters

string $entity_type: The entity type to export. If a wrong content entity type is entered, module displays a list of all content entity types.

array $options: An associative array of options whose values come from cli, aliases, config, etc.

Throws

\Exception

File

src/Commands/DefaultContentDeployCommands.php, line 162

Class

DefaultContentDeployCommands
Class DefaultContentDeployCommands.

Namespace

Drupal\default_content_deploy\Commands

Code

public function contentDeployExportWithReferences($entity_type, array $options = [
  'entity_id' => NULL,
  'bundle' => NULL,
  'skip_entities' => NULL,
  'force-update' => FALSE,
  'folder' => self::OPT,
]) {
  try {
    $entity_ids = $this
      ->processingArrayOption($options['entity_id']);
    $skip_ids = $this
      ->processingArrayOption($options['skip_entities']);
    $this->exporter
      ->setEntityTypeId($entity_type);
    $this->exporter
      ->setEntityBundle($options['bundle']);
    if (!empty($options['folder'])) {
      $this->exporter
        ->setFolder($options['folder']);
    }
    $this->exporter
      ->setMode('reference');
    $this->exporter
      ->setForceUpdate($options['force-update']);
    if ($entity_ids) {
      $this->exporter
        ->setEntityIds($entity_ids);
    }
    if ($skip_ids) {
      $this->exporter
        ->setSkipEntityIds($skip_ids);
    }
    $result = $this->exporter
      ->export()
      ->getResult();
    $this
      ->displayExportResult($result);
  } catch (\InvalidArgumentException $e) {
    $content_entity_list = $this
      ->getAvailableEntityTypes();
    $this->logger
      ->error($e
      ->getMessage());
    $this->logger
      ->notice(dt('List of available content entity types:@types', [
      '@types' => PHP_EOL . $content_entity_list,
    ]));
  }
}