Generating dummy Drupal content with Devel & more

10 Oct 2021

CMSs like Drupal offer website owners unlimited opportunities to add as much content as they need and when they need it. However, at the stage of website building, when developers and themers are creating layouts, Views, and other things that shape the content structure, there is often no content ready yet.

How to test everything well in various scenarios without content available? Developers or QA engineers are not editors — generating nodes for testing purposes can be a tedious task for them. Luckily, it is possible to “invite” an instant content generation assistant to your website. Just a few clicks will be needed for filling the site with as many dummy entities as needed.

This assistant is one of the favorite modules of Drupal developers — the Devel. In this post, we will take a tour of how to create dummy Drupal content with the Devel module, how to make the content as realistic as possible with yet another Devel-related module — the Realistic Dummy Content, and how to use Drush commands for the same purposes if you prefer the Drupal console.

Automatic dummy Drupal content generation

Introduction to the Devel Generate module

The Devel module has multiple missions in enhancing a developer’s workflows, content generation being just one of them. For this purpose, we will mostly need the Devel Generate module that the Devel module comes packed with.

The module generates entities based on their structure, field by field. For example, if there is an image field, it will add an image placeholder in the form of a colored block. The text will be generated in fake Latin that resembles a phrase familiar to many readers — “Lorem ipsum dolor sit amet…” widely used to substitute the real text.

You don’t want to see something like this on live websites, that’s why developers prefer to disable the Devel Generate module on the production environment (we have touched upon this in our blog post about the partially shared Drupal configuration).

Speaking about Devel Generate, we are mostly using the word “content” to express the general idea of this automatic generation feature. However, to be more specific, Devel can also generate media, menus, users, taxonomy terms, and taxonomy vocabularies on your Drupal website. While doing this, the module offers many settings to make the process as accurate and useful as possible. We will discuss them right now in the next part that explains how to work with Devel in Drupal.

One of the most prominent Devel features is Drush integration so it will be possible to choose between generating nodes via the UI or via the command-line interface.

How to generate dummy Drupal content with the Devel Generate

1) Installing the module

Install the Devel module just like any other and enable the Devel and the Devel Generate modules.

2) Generating dummy Drupal content

Next, go to the Configuration tab of your Drupal dashboard and you will see the Generate section. First, it allows you to choose which Drupal elements to generate. Let’s generate content.

In the settings, you can:

  • delete all nodes of the selected types before generating new nodes (be careful, it clear all the nodes, not just Devel-generated)
  • select specific content types
  • choose the number of nodes to generate
  • choose how far back the node publication date should go
  • set the maximum number of comments to nodes
  • set the maximum words in titles
  • prefix the title with the content type label
  • add a URL alias for each node
  • select the primary language (if your website is multilingual)
  • select users to be assigned as node authors

The last step is to click “Generate,” wait a couple of moments while you see the notice that nodes are in the process of being generated, and then check your website and make sure it’s full of newly created nodes.

Using the Realistic Dummy Content module

While developers are used to seeing Devel-generated nodes, customers do not find it so attractive when they are shown the future layouts and structures. What about making autogenerated nodes look more realistic? For this purpose, there is the Realistic Dummy Content module. It is a separate module although it only works with the Devel and the Devel Generate submodule installed.

Here are the key differences between the Devel Generate and the Realistic Dummy Content:

  • Unlike the Devel Generate that uses fake Latin for titles, the Realistic Dummy Content names nodes “first title,” “second title,” etc.
  • The Realistic Dummy Content applies simple formatting inside the nodes (bold, italics, etc.) to make them look more like human-generated nodes.
  • While the Devel Generate creates colored blocks for images, the Realistic Dummy Content uses freely-licensed stock photos for images and user profile pictures.

If you prefer to avoid the stock images provided by the module, there is an option to disable the Realistic Dummy Content submodule and only use the Realistic Dummy Content API submodule together with your custom module.

After installing the Realistic Dummy Content module, you will see the two new modules directly under the Devel and the Devel Generate on the Extend tab. These are Realistic Dummy Content and Realistic Dummy Content API. You will need all four of these enabled.

The interface will not differ from that of the Devel Generate — similarly, you will find the Generate subsection in the Configuration section and see the same settings for content generation. However, the final results will differ. This looks more realistic than what we have seen before, doesn’t it?

Using Drush to generate new content

Drupal console lovers can now start reading more attentively because we will discuss the Drush commands for auto-generating content.
The generate-content command (genc for short), can be used with two arguments: the number of nodes to generate and the maximum number of comments to the nodes. For example, this will generate 40 nodes with a maximum of 3 comments for each.

$ drush genc 40 3

If you want to delete the previously created nodes, add --kill to the command:

$ drush genc 50 4 --kill

If you want to generate content of a specific type, add --types to the command. If type is not added, there will be articles and basic pages generated by default.

$ drush genc 50 4 --types=blog, article

There also are such options as

  • --feedback : An integer that represents an interval for insertion rate logging. The default is 1000
  • --skip-fields : List of fields separated by commas that should be omitted during the automatic generation
  • --languages : List of language codes separated by commas

Just like there is a command for node generation, there are ones for other entity types:

  • drush generate-menus (drush genm)
  • drush generate-terms (drush gent)
  • drush generate-users (drush genu)
  • drush generate-vocabs (drush genv)

Let automatic content generation be helpful to you!

No matter if you prefer to generate dummy content in Drupal with Devel Generate or Realistic Dummy Content via the interface or the corresponding Drush commands, you need to keep in mind that these procedures require caution. They are recommended only for test websites, especially if you want to use the delete option as well.

However, if implemented carefully, automatic content generation can significantly help you with testing the content structures and presenting the demos to the customer. Let developers free themselves from tedious and pointless manual work and spend their energy on the most creative and useful tasks for the total customer’s satisfaction!