function drush_default_content_export_references in Default Content for D8 8
Same name and namespace in other branches
- 2.0.x 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 77 - Drush integration for the default_content module.
Code
function drush_default_content_export_references($entity_type_id, $entity_id = NULL) {
/** @var \Drupal\default_content\DefaultContentExporterInterface $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) {
$serialized_by_type = $exporter
->exportContentWithReferences($entity_type_id, $entity_id);
$exporter
->writeDefaultContent($serialized_by_type, $folder);
}
}