Default Content¶
Using the Default Content module¶
The export process is the same for modules and recipes. Let’s review that now.
Getting set up¶
Install the module as you normally would. If using the module for creating content for recipes, install it in the dev section of your composer requirements as it is not needed in production.
And enable the module: The module doesn’t have a user interface. Instead, it provides drush commands that can be run to export content.What can we export?¶
Out of the box, we can export the following entity types:
- Content type nodes: node
- Taxonomy Terms: taxonomy_term
- Files: file
- Media: media
- Menu Links: menu_link_content
- Content blocks: block_content
- Shortcuts: shortcut
At this time, there isn’t a way to export by bundle type, think all nodes of type Article, or all menu links from the main menu, but there is a patch for it.
Let’s take a look at the three commands that the module provides to export content.
Default content drush commands¶
default-content-export-references¶
Exports an entity and all its referenced entities. This is my go to command as it helps you export referenced media, files, taxonomy terms, and users from the parent node.
Alias: * dcer
Arguments: * entity_type – The entity type to export. * entity_id – The ID of the entity to export
One of these arguments is required.
Options:
- folder – The module or recipe’s content folder to export to. Entities are automatically grouped by entity type into directories.
Examples:
# Exports node 123 and all its dependencies.
# To a module:
drush dcer node 123 module_name
# To a recipe:
drush dcer node 123 --folder=recipes/recipe_name/content
# Export all nodes and all their dependencies.
drush dcer node --folder=modules/custom/my_custom_module/content
default-content-export¶
Exports a single entity. If you want to manage your own dependencies.
Alias: * dce
Arguments: * entity_type – The entity type to export. * entity_id – The ID of the entity to export
Both of these arguments are required.
Options: * file – Write out the exported content to a file instead of stdout
Examples:
default-content-export-module¶
Exports all the content defined in a module info file. This is most helpful for distribution and install profile maintainers where they would want to maintain and update default content from a canonical source.
Alias: * dcem
Arguments: * module – The machine name of the module
The argument is required.
Options: * None
Examples:
# Exports all the content defined in a module info file.
drush dcem module_name
# The module's info file would need to have a section like this:
default_content:
node:
- c9a89616-7057-4971-8337-555e425ed782
- b6d6d9fd-4f28-4918-b100-ffcfb15c9374
file:
- 59674274-f1f5-4d6a-be00-fecedfde6534
- 0fab901d-36ba-4bfd-9b00-d6617ffc2f1f
media:
- ee63912a-6276-4081-93af-63ca66285594
- bcb3c719-e266-45c1-8b90-8f630f86dcc7
menu_link_content:
- 9fbb684c-156d-49d6-b24b-755501b434e6
- 19f38567-4051-4682-bf00-a4f19de48a01
block_content:
- af171e09-fcb2-4d93-a94d-77dc61aab213
- a608987c-1b74-442b-b900-a54f40cda661