You are here

function drush_default_content_export_references in Default Content for D8 2.0.x

Same name and namespace in other branches
  1. 8 drush/default_content.drush.inc \drush_default_content_export_references()

Exports a piece of content and all its referenced entities.

Parameters

string $entity_type_id: The entity type ID.

mixed $entity_id: (Optional) The entity ID to export or all entities will be exported.

File

drush/default_content.drush.inc, line 74
Drush integration for the default_content module.

Code

function drush_default_content_export_references($entity_type_id, $entity_id = NULL) {

  /** @var \Drupal\default_content\ExporterInterface $exporter */
  $exporter = \Drupal::service('default_content.exporter');
  $folder = drush_get_option('folder', '.');
  if (is_null($entity_id)) {
    $entities = \Drupal::entityQuery($entity_type_id)
      ->execute();
  }
  else {
    $entities = [
      $entity_id,
    ];
  }

  // @todo Add paging.
  foreach ($entities as $entity_id) {
    $exporter
      ->exportContentWithReferences($entity_type_id, $entity_id, $folder);
  }
}