Since the Devel module allows to generate content only for core entities:

Accelerate development of your site or module by quickly generating nodes, comments, terms, users, and more.

Is there a module or a proper way to generate fake content for custom entities?

I mention that I found Devel contrib module that includes the Devel Contrib Generate module, which allows generating of dummy entities of any entity type, but I've not been able to figure out how to use it with D8.

  • I usually write a migration and create a CSV of dummy content to import it from. Since I'll almost always need a migration to import real content, eventually, I might as well write the migration. I suppose it depends what your aim is. Migrate will serve the purpose of giving you repeatably roll-back-able, import-able dummy data for dev/testing purposes, but it won't spare you the task of actually generating the dummy data that goes into the CSV. Jan 28, 2020 at 22:07

2 Answers 2


I've just wrote a blog post on this topic, it's in french but the code should be easily understandable : https://kgaut.net/snippets/2021/drupal-utiliser-devel-generate-pour-generer-des-entites-personalisees.html

You can write a plugin that extend DevelGenerateBase, I used ExampleDevelGenerate as an inspiration : https://api.drupal.org/api/devel/devel_generate%21tests%21modules%21devel_generate_example%21src%21Plugin%21DevelGenerate%21ExampleDevelGenerate.php/class/ExampleDevelGenerate/8.x-1.x


To create some demo entities programmatically, you can use a while loop in your function. To create 100 entities:

$i = 1;
while ($i <= 100) {

  // Create an entity here.  See https://www.drupal.org/docs/8/api/entity-api/working-with-the-entity-api#s-create
  // To create random strings (e.g. for fake titles), refer to the comments at https://www.php.net/manual/en/function.rand.php -- In here you will find different ways to create random strings.
  // Generate some Lorem Ipsum text if you like: https://stackoverflow.com/a/20633400/861826


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.