public function DefaultContentCommands::contentExportReferences in Default Content for D8 8
Same name and namespace in other branches
- 2.0.x src/Commands/DefaultContentCommands.php \Drupal\default_content\Commands\DefaultContentCommands::contentExportReferences()
Exports an entity and all its referenced entities.
@command default-content:export-references @option folder Folder to export to, entities are grouped by entity type into directories. @aliases dcer
Parameters
string $entity_type_id: The entity type to export.
int $entity_id: The ID of the entity to export.
File
- src/
Commands/ DefaultContentCommands.php, line 67
Class
- DefaultContentCommands
- Class DefaultContentCommands.
Namespace
Drupal\default_content\CommandsCode
public function contentExportReferences($entity_type_id, $entity_id = NULL, $options = [
'folder' => NULL,
]) {
$folder = $options['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 = $this->defaultContentExporter
->exportContentWithReferences($entity_type_id, $entity_id);
$this->defaultContentExporter
->writeDefaultContent($serialized_by_type, $folder);
}
}