Commit c914f043 authored by larowlan's avatar larowlan

Merge pull request #53 from andypost/8.x-1.x-export-all

Export all option
parents 4a484537 2ba10aa7
......@@ -31,7 +31,7 @@ function default_content_drush_command() {
'folder' => dt('Folder to export to, entities are grouped by entity type into directories.'),
],
'aliases' => ['dcer'],
'required-arguments' => 2,
'required-arguments' => 1,
];
$items['default-content-export-module'] = [
'description' => dt('Exports all the content defined in a module info file.'),
......@@ -72,16 +72,24 @@ function drush_default_content_export($entity_type_id, $entity_id) {
* @param string $entity_type_id
* The entity type ID.
* @param mixed $entity_id
* The entity ID to export.
* (Optional) The entity ID to export or all entities will be exported.
*/
function drush_default_content_export_references($entity_type_id, $entity_id) {
function drush_default_content_export_references($entity_type_id, $entity_id = NULL) {
/** @var \Drupal\default_content\DefaultContentManagerInterface $manager */
$manager = \Drupal::service('default_content.manager');
$folder = drush_get_option('folder', '.');
$serialized_by_type = $manager->exportContentWithReferences($entity_type_id, $entity_id);
$manager->writeDefaultContent($serialized_by_type, $folder);
if (is_null($entity_id) && ($entities = \Drupal::entityQuery($entity_type_id)->execute())) {
// @todo Add paging.
foreach ($entities as $entity_id) {
$serialized_by_type = $manager->exportContentWithReferences($entity_type_id, $entity_id);
$manager->writeDefaultContent($serialized_by_type, $folder);
}
}
else {
$serialized_by_type = $manager->exportContentWithReferences($entity_type_id, $entity_id);
$manager->writeDefaultContent($serialized_by_type, $folder);
}
}
/**
......
......@@ -338,7 +338,8 @@ class DefaultContentManager implements DefaultContentManagerInterface {
if ($dependent_entity instanceof ConfigEntityInterface) {
unset($entity_dependencies[$id]);
}
else {
elseif (!isset($entity_dependencies[$id])) {
// Prevent loops.
$entity_dependencies = array_merge($entity_dependencies, $this->getEntityReferencesRecursive($dependent_entity, $depth + 1));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment