Last updated March 21, 2017. Created on September 28, 2016.
Edited by jimconte, eelkeblok, RajabNatshah. Log in to edit this page.

Default content gives your module and install profile a way to ship default content as well as configuration. It does so by leveraging core's serialization, rest and hal modules. It supports entity-references between content as well as files if you have File entity. Content export works with a set of drush commands (more on those below).

How does it work

Enable default content first. Any module that requires default content can put hal+json versions of the entities (created with the drush commands) inside content/{entity_type} folders.

For example, have a look at default_content_test, which has:

  • modules/default_content_test/content
  • modules/default_content_test/content/node
  • modules/default_content_test/content/node/imported.json
  • modules/default_content_test/content/taxonomy_term
  • modules/default_content_test/content/taxonomy_term/tag.json

Drush commands

The following drush commands are supported.

default-content-export

Exports a single entity.

Arguments
  • entity_type The entity type to export.
  • entity_id The ID of the entity to export.
Options
  • file Write out the exported content to a file instead of stdout
Aliases
dce

Both the entity-type and the node-id must be provided. By default the exported entity is printed to stdout(), but can also be saved to a file using the file option.

Examples

$ drush dce node 123 my_default_content_module

Or with other entity types.

$ drush dce node <node id> my_default_content_module
$ drush dce taxonomy_term <taxonomy term id> my_default_content_module
$ drush dce file <file id> my_default_content_module
$ drush dce media <media id> my_default_content_module
$ drush dce menu_link_content <menu link id> my_default_content_module
$ drush dce block_content <block id> my_default_content_module

default-content-export-references

Exports an entity and all its referenced entities.

Arguments
  • entity_type The entity type to export.
  • entity_id The ID of the entity to export.
Options
  • folder Folder to export to, entities are grouped by entity type into directories.
Aliases
dcer

Both the entity-type and the node-id must be provided. By default the exported entities are saved to folders named after the filetype in Drupal's root directory. The --folder option first creates a parent folder (again in the root directory) and then adds the content-type folders to it.

Example

$ drush dcer node 123 --folder=modules/custom/my_default_content_module/content

default-content-export-module

Exports all content defined in a module info file. A module's .info.yml-file can contain a section with default files. This command will export the files mentioned in that section.

Arguments
  • module The name of the module.
Aliases
dcem

Example

Relevant contents of my_default_content_module.info.yml:

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
  

Export this content with:

$ drush dcem my_default_content_module

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

jimconte’s picture

The module works great with dependencies, makes the job very easy. Thank you.
However, please update your example, when exporting to a defined folder:
$ drush dcer node 123 my_default_content_module
Should really be
$ drush dcer node 123 --folder=modules/custom/my_default_content_module/content
or something similar.