Generated content
Generated content provides a plugin-based system for programmatically generating deterministic content entities. Unlike random dummy content, generated content produces reproducible sets useful for visual regression testing and consistent demo environments.
This page covers how Vortex uses the module. The module documentation is the reference for its full API.
Plugin system
Content generators are PHP classes placed in a module's
src/Plugin/GeneratedContent/ directory, annotated with the #[GeneratedContent]
attribute.
Creating a plugin
namespace Drupal\ys_demo\Plugin\GeneratedContent\Node;
use Drupal\generated_content\Attribute\GeneratedContent;
use Drupal\generated_content\Plugin\GeneratedContent\GeneratedContentPluginBase;
#[GeneratedContent(
id: 'ys_demo_node_page',
entity_type: 'node',
bundle: 'page',
weight: 20,
)]
class Page extends GeneratedContentPluginBase {
public function generate(): array {
$entities = [];
$storage = $this->entityTypeManager->getStorage('node');
for ($i = 1; $i <= 20; $i++) {
$node = $storage->create([
'type' => 'page',
'title' => sprintf('Demo page %s %s', $i, $this->helper::staticName()),
'status' => 1,
]);
$node->set('body', [
'value' => $this->helper::staticRichText(3),
'format' => 'full_html',
]);
$node->save();
$entities[] = $node;
}
return $entities;
}
}
Attribute parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | yes | Unique plugin ID |
entity_type | string | yes | Target entity type (node, taxonomy_term, etc.) |
bundle | string | yes | Target bundle |
weight | int | no | Execution order (lower = earlier) |
tracking | bool | no | Track created entities for cleanup (default: TRUE) |
label | TranslatableMarkup | no | Human-readable name shown in the admin UI |
helper | string | no | Custom helper class extending GeneratedContentHelper |
Generation helpers
$this->helper is a GeneratedContentHelper singleton that produces field
values, creates file assets, and looks up entities that earlier plugins
created. The examples below are a sample of what it offers - the module
documentation lists the full set.
Static helpers return the same values on every run, which is what visual regression testing needs:
$this->helper::staticName(); // Fixed-length name.
$this->helper::staticSentence(5); // Sentence of 5 words.
$this->helper::staticRichText(3); // 3 paragraphs of HTML.
Random helpers vary on every run, which suits content that only needs to make the site look populated:
$this->helper::randomName();
$this->helper::randomSentence(5, 10); // Between 5 and 10 words.
$this->helper::randomEmail();
$this->helper::randomTimestamp('-1year', 'now');
Entity helpers reference content that earlier plugins produced. Use
weight to make sure those plugins ran first, and pick the static variant
when the reference itself must stay stable between runs:
// In a node plugin with weight: 20 (runs after terms at weight: 10).
$node->set('field_tags', $this->helper::randomTerms('tags', 3));
$node->set('field_author', $this->helper::staticUser());
Asset helpers create managed files from the dummy assets that ship with the module, covering image, document, audio and video extensions:
$node->set('field_image', $this->helper::createFile('png'));
$node->set('field_attachment', $this->helper::createFile('pdf'));
Triggering generation
Drush command
drush generated-content:create-content
drush generated-content:create-content node page
Admin UI
Visit /admin/config/development/generated-content to generate content through
the admin interface.
Environment variable
Set GENERATED_CONTENT_CREATE=1 before provisioning to auto-generate content
on module install. Optionally filter:
GENERATED_CONTENT_ITEMS="taxonomy_term-tags,node-page"
Provisioning
Vortex installs the module from
scripts/provision-10-enable-dev-modules.sh in the local, ci, dev and
stage environments, passing GENERATED_CONTENT_CREATE=1 so the content is
created as part of the install. Setting DRUPAL_GENERATED_CONTENT_SKIP=1
installs the module without the content.
➡️ See Generated content in the provisioning documentation.
Example in Vortex
The ys_demo module ships a single generated content plugin,
Page:
it creates 20 page nodes whose titles and body text come from the static
helpers, so the same pages appear on every rebuild. The nodes back the demo
/pages view used by the Testmode example.