Generator Engine is a tool that creates dummy content, taxonomy terms, and user accounts to populate a Drupal site quickly for development and QA purposes. It can generate these entities from an admin form, JSON or YAML documents, Drush commands, or via HTTP requests. This module should only be used on non-production sites and uninstalled before going live.
Generator Engine creates dummy content entities nodes, taxonomy terms users so developers and QA can populate a site quickly. It
can generate from an admin form, from a JSON or YAML document, from
Drush, or over HTTP. You choose which entity types and bundles may be
generated, and which of their fields take part, then submit a generation
document describing what to create. This module creates
arbitrary content and user accounts and writes uploaded files. Use it on
development and QA sites only, and uninstall it before going to
production.
Installation
Install as you would normally install a contributed Drupal module.
See Installing
modules. The project ships one required module and three optional
sub-modules:
Module Purpose
generator_engine
The engine, the admin forms and the Drush commands.
generator_engine_api
JSON/YAML/file HTTP endpoints for the generation pipeline.
generator_engine_api_rest
The same endpoints as REST resource plugins. Requiresgenerator_engine_api.
generator_engine_batch
Adds a “Generated batch” content type that collects the entitiesproduced by each run.
Configuration
- Grant the Administer Generator Engine permission.
It is marked as a restricted permission: it allows creating arbitrary
content and user accounts, so grant it only to trusted roles on
non-production sites. - Visit /admin/generate/config and select the entity
types and bundles that may be generated. - Visit /admin/generate/config/forms to choose which
form displays drive the per-bundle generation form.
Settings live in generator_engine.settings:
Generating entities
From the UI
- /admin/generate/entities — a per-bundle form built
from your field configuration. - /admin/generate/json/highlighter — submit a JSON
generation document. - /admin/generate/yaml/highlighter — submit a YAML
generation document.
Using PHP Code
$target_entities = [
'node_type' => [
"page" => [ // <== another bundle name like article or basic page
"check" => 1,
"count" => 3,
"fields" => [
"title" => '%lorem_title',
"body" => '%lorem_paragraph',
],
],
]
];
$result = \Drupal::service('generator_engine.helpers')->generateEngine($target_entities);
$target_entities = [
'node_type' => [
"article" => [ // <== bundle name like article or basic page
"check" => 1, // <== flag to execute the generation for this statement or not
"count" => 5, // <== number of generated entities
"fields" => [// <== fields (name, values) that will used in the generation process. Generated from the 'custom_fields' section in generation form
"title" => '%lorem_title',
"body" => '%lorem_paragraph',
"field_tags" => "!random_single", // <== single value of list
"field_image" => '$image',
],
"properties" => [// <== fields (name, values) that will used in the generation process. Generated from the 'proprties' section in generation form
"uid" => null,
"status" => 0, // <== publish status of the node
],
]
]
];
$target_entities = [
"taxonomy_vocabulary" => [ // <== another entity type
"tags" => [ // target vocabulary
"check" => 1,
"count" => 2,
"fields" => [
"name" => "%lorem_title",
],
"properties" => [],
]
]
];
$target_entities = [
"user" => [ // user entity type
"user" => [
"check" => 1,
"count" => 5,
],
],
];
From Drush
drush generator_engine:generate <file>
Runs the same pipeline as the JSON and YAML forms. The format is
detected from the file extension, or forced with
--format=json|yaml|php. Pass - to read from
stdin, which requires --format.
Aliases: ge-generate, ge-gen.
drush generator_engine:generate assets/samples/sample-target-entities.json
drush generator_engine:generate assets/samples/sample-target-entities.yml
drush generator_engine:generate assets/samples/sample-target-entities.php --format=php
cat data.yml | drush generator_engine:generate - --format=yamlA second command seeds users, taxonomy terms and content authored by
and tagged with them:
drush generator_engine:seed_users_tags_content --users_count=2 --tags_count=6
Alias: ge-seed-utc.
The php format executes the named file so it can define
$target_entities. It is available from Drush only and is
never selected by the HTTP endpoints.
Over HTTP
Enable generator_engine_api, then turn on Enable
JSON/YAML generation APIs at
/admin/generate/config. The endpoints accept
POST and require the
administer generator engine permission:
/api/generator-engine/json/api/generator-engine/yaml/api/generator-engine/file
Enabling generator_engine_api_rest additionally exposes
them as REST resource plugins under
/api/generator-engine/rest/{json,yaml,file}.
Both Basic Auth and cookie authentication are accepted.
Cookie-authenticated requests must send an X-CSRF-Token
header, which you can obtain from /session/token. Basic
Auth requests do not need one.
See modules/generator_engine_api/README.md and
modules/generator_engine_api_rest/README.md for the request
and response shapes.
The generation document
A generation document is a map of entity type to bundle to a
statement:
node_type:
article:
check: 1 # generate this bundle
count: '3' # how many
fields:
title: 'My article'
field_tags: '!random_single'
properties:
uid: null # author; null means the current user
fields holds values for the bundle’s configured fields;
properties holds entity properties such as uid
and status.
ref|field
The value for the current iteration.
ref!|field
Always the first item.
ref$|field
A random item.
Worked examples of every format are in
assets/samples/:
sample-target-entities.{json,yml,php}— a basic
statement.sample-target-entities-article-tags.{json,yml,php}—
fields and references.sample-target-entities-dependant.{json,yml,php}—
ordered dependent parts.
Extending
Four alter hooks let another module register its own bundles and
fields, adjust generated values, and react to saved entities. They are
documented with examples in generator_engine.api.php:
hook_generator_engine_entities_config_alter()hook_generator_engine_entity_data_alter()hook_generator_engine_entity_generated()hook_generator_engine_bundle_generated()
Ask your assistant about Generator Engine
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.