function Exporter::exportWithDependencies
Exports an entity and all of its dependencies to a directory.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to export.
string $destination: A destination path or URI; will be created if it does not exist. Subdirectories will be created for each entity type that is exported.
Return value
int The number of entities that were exported.
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ Exporter.php, line 159
Class
- Exporter
- Handles exporting content entities.
Namespace
Drupal\Core\DefaultContentCode
public function exportWithDependencies(ContentEntityInterface $entity, string $destination) : int {
$queue = [
$entity,
];
$done = [];
while ($queue) {
$entity = array_shift($queue);
$uuid = $entity->uuid();
// Don't export the same entity twice, both for performance and to prevent
// an infinite loop caused by circular dependencies.
if (isset($done[$uuid])) {
continue;
}
$dependencies = $this->exportToFile($entity, $destination)->metadata
->getDependencies();
foreach ($dependencies as $dependency) {
$dependency = $this->entityRepository
->loadEntityByUuid(...$dependency);
if ($dependency instanceof ContentEntityInterface) {
$queue[] = $dependency;
}
}
$done[$uuid] = TRUE;
}
return count($done);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.