Creating default content for easier testing on Drupal 8

While working with Drupal 7 we had some development workflows that worked very well for us and now we want to adapt those workflows to the new major version of Drupal.

One of this "development features" as you may call them was the possibility of having some predefined content that can be recreated at any time to test the site. For example you don't have to worry about creating new users that represent the different roles every time you set up a fresh site, they will be there.

We used to do this on Drupal 7 with our own module called migrate_default_content and we decided to make a Drupal 8 port.

Migrate import

Main features of this module:

- Have your test content on files under version control. Avoid database dumps.

- Recreate your content easily in any environment.

- Relies on the migrate API so we can handle dependencies between content, references, reverting and recreating.

- Support for any entity type that migrate can create.


Although we aimed for a straight port of the module we added some improvements over the D7 module:

- Now we don't need to specify the structure of the migration on a YAML, is retrieved from the headers of the CSV file but if you want to configure the migration in a different way a configuration YAML file can be written to overwrite the one that is created on the fly.

- Use Symfony YAML parser included in core and leverage other APIs to generate the behaviour of the migration like event subscriptions.

- Set the first column as source id for migrations so the uuid can be used instead of a static id.

Plans for the future.

While writing some CSV files to serve as examples it became clear that a "plain" structure like CSV doesn't fit the Drupal data model. Fields with subcomponents like a body with a format and a summary or simply a multivalued field require the use of separator or a nested structure. The most promising candidate for replacing CSV is JSON with the added advantage that we can directly use the output of a REST webservice to export to code the content we generate on the Drupal interface.

You can test this module today so if you have an entity type or field that needs special handling it can be easily added by opening an issue.


We released it with a free software license and some documentation on how to use but don't hesitate to contact us to learn more.