public function Exporter::exportModuleContent in Default Content for D8 2.0.x
Same name and namespace in other branches
- 8 src/Exporter.php \Drupal\default_content\Exporter::exportModuleContent()
Exports all of the content defined in a module's info file.
Parameters
string $module_name: The name of the module.
string|null $folder: (optional) A folder to write the exported entities into, grouped by entity type. File entities also export their files into the same folder.
Return value
string[][] The serialized entities keyed by entity type and UUID.
Throws
\InvalidArgumentException If any UUID is not found.
Overrides ExporterInterface::exportModuleContent
File
- src/
Exporter.php, line 160
Class
- Exporter
- A service for handling import of default content.
Namespace
Drupal\default_contentCode
public function exportModuleContent($module_name, $folder = NULL) {
$info_file = $this->moduleHandler
->getModule($module_name)
->getPathname();
$info = $this->infoParser
->parse($info_file);
$exported_content = [];
if (empty($info['default_content'])) {
return $exported_content;
}
foreach ($info['default_content'] as $entity_type => $uuids) {
foreach ($uuids as $uuid) {
$entity = $this->entityRepository
->loadEntityByUuid($entity_type, $uuid);
if (!$entity) {
throw new \InvalidArgumentException(sprintf('Entity "%s" with UUID "%s" does not exist', $entity_type, $uuid));
}
$exported_content[$entity_type][$uuid] = $this
->exportContent($entity_type, $entity
->id());
if ($folder) {
$this->contentFileStorage
->writeEntity($folder, $exported_content[$entity_type][$uuid], $entity);
}
}
}
return $exported_content;
}