default_content.drush.inc in Default Content for D8 2.0.x
Same filename and directory in other branches
Drush integration for the default_content module.
File
drush/default_content.drush.incView source
<?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'),
],
'aliases' => [
'dce',
],
'required-arguments' => 2,
];
$items['default-content-export-references'] = [
'description' => dt('Exports an entity and all its referenced entities.'),
'arguments' => [
'entity_type' => dt('The entity type to export.'),
'entity_id' => dt('The ID of the entity to export.'),
],
'options' => [
'folder' => dt('Folder to export to, entities are grouped by entity type into directories.'),
],
'aliases' => [
'dcer',
],
'required-arguments' => 1,
];
$items['default-content-export-module'] = [
'description' => dt('Exports all the content defined in a module info file.'),
'arguments' => [
'module' => dt('The name of the module.'),
],
'aliases' => [
'dcem',
],
'required-arguments' => 1,
];
return $items;
}
/**
* Exports a piece of content into the stdout or into a file.
*
* @param string $entity_type_id
* The entity type ID.
* @param mixed $entity_id
* The entity ID to export.
*/
function drush_default_content_export($entity_type_id, $entity_id) {
/** @var \Drupal\default_content\ExporterInterface $exporter */
$exporter = \Drupal::service('default_content.exporter');
$export = $exporter
->exportContent($entity_type_id, $entity_id, drush_get_option('file'));
if (!drush_get_option('file')) {
drush_print($export);
}
}
/**
* Exports a piece of content and all its referenced entities.
*
* @param string $entity_type_id
* The entity type ID.
* @param mixed $entity_id
* (Optional) The entity ID to export or all entities will be exported.
*/
function drush_default_content_export_references($entity_type_id, $entity_id = NULL) {
/** @var \Drupal\default_content\ExporterInterface $exporter */
$exporter = \Drupal::service('default_content.exporter');
$folder = drush_get_option('folder', '.');
if (is_null($entity_id)) {
$entities = \Drupal::entityQuery($entity_type_id)
->execute();
}
else {
$entities = [
$entity_id,
];
}
// @todo Add paging.
foreach ($entities as $entity_id) {
$exporter
->exportContentWithReferences($entity_type_id, $entity_id, $folder);
}
}
/**
* Exports all of the content for a given module.
*
* @param string $module_name
* The module name to export.
*/
function drush_default_content_export_module($module_name) {
/** @var \Drupal\default_content\ExporterInterface $exporter */
$exporter = \Drupal::service('default_content.exporter');
$module_folder = \Drupal::moduleHandler()
->getModule($module_name)
->getPath() . '/content';
$exporter
->exportModuleContent($module_name, $module_folder);
}
Functions
Name | Description |
---|---|
default_content_drush_command | Implements hook_drush_command(). |
drush_default_content_export | Exports a piece of content into the stdout or into a file. |
drush_default_content_export_module | Exports all of the content for a given module. |
drush_default_content_export_references | Exports a piece of content and all its referenced entities. |