function drush_defaultcontent_export in Default Content 8
Exports a piece of content into a odule's content/ directory.
Parameters
string $entity_type_id: The entity type ID.
$entity_id: The entity ID to export.
File
- drush/
defaultcontent.drush.inc, line 38 - Drush integration for the defaultcontent module.
Code
function drush_defaultcontent_export($entity_type_id, $entity_id, $module) {
$manager = \Drupal::service('defaultcontent.manager');
if (drush_get_option('ref')) {
$entities = $manager
->exportContentWithReferences($entity_type_id, $entity_id);
}
else {
$entities = $manager
->exportContentWithMenuLinks($entity_type_id, $entity_id);
}
$dir = drupal_get_path('module', $module) . '/content';
foreach ($entities as $entity_type_id => $serialized_entities) {
//store contentEntities in json oand configEntities in yml
//@todo how do we determine, from the entity_type_id, if it is a contentEntity?
$ext = $entity_type_id == 'node' ? 'json' : 'yml';
// Ensure that the folder per entity type exists.
$entity_type_dir = "{$dir}/{$entity_type_id}";
if (file_prepare_directory($entity_type_dir, FILE_CREATE_DIRECTORY)) {
foreach ($serialized_entities as $entity_id => $serialized_entity) {
$filename = $entity_type_dir . '/' . $entity_id . '.' . $ext;
file_put_contents($filename, $serialized_entity);
print dt('Written file @file', [
'@file' => $filename,
]) . "\n";
}
}
else {
print dt('Could not write file') . "\n";
}
}
}