Commit 72978c80 authored by dawehner's avatar dawehner

add a initial drush version

parent e148ecd1
<?php
/**
* @file
* Drush integration for the default_content module.
*/
/**
* Implements hook_drush_command().
*/
function default_content_drush_command() {
$items['default-content-export'] = [
'description' => dt('Exports a single entity'),
'arguments' => [
'entity_type' => dt('The entity type to export.'),
'entity_id' => dt('The ID of the entity to export.'),
],
'options' => [
'file' => dt('Write out the exported content to a file instead of stdout'),
],
'required-arguments' => 2,
];
return $items;
}
/**
* Exports a piece of content into the stdout or into a file.
*
* @param string $entity_type_id
* The entity type ID.
* @param $entity_id
* The entity ID to export.
*
* @return string
* The rendered export as hal.
*/
function drush_default_content_export($entity_type_id, $entity_id) {
/** @var \Drupal\default_content\DefaultContentManagerInterface $manager */
$manager = \Drupal::service('default_content.manager');
$export = $manager->exportContent($entity_type_id, $entity_id);
if ($file = drush_get_option('file')) {
file_put_contents($file, $export);
}
else {
drush_print($export);
}
}
......@@ -155,6 +155,16 @@ class DefaultContentManager implements DefaultContentManagerInterface {
return $created;
}
/**
* {@inheritdoc}
*/
public function exportContent($entity_type_id, $entity_id) {
$storage = $this->entityManager->getStorage($entity_type_id);
$entity = $storage->load($entity_id);
return $this->serializer->serialize($entity, 'hal_json', ['json_encode_options' => JSON_PRETTY_PRINT]);
}
/**
* Utility to get a default content scanner
*
......
......@@ -31,4 +31,17 @@ interface DefaultContentManagerInterface {
*/
public function importContent($module);
/**
* Exports a single entity as importContent expects it.
*
* @param string $entity_type_id
* The entity type ID.
* @param $entity_id
* The entity ID to export.
*
* @return string
* The rendered export as hal.
*/
public function exportContent($entity_type_id, $entity_id);
}
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