NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist
Packagist, #672 most downloaded on Packagist
Drupal code generator
Latest stable
4.2.0
Last release 1 years ago
01 Jun 2025
Release timing varies
gaps range from 2 weeks to 7 months
Most releases are documented
notes for 50 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
121 releases · first in 2015
Drag across the ruler to compare, or tap a release to open it.
Instead of annotations, the field plugins generated now use attributes.
Instead of annotations, the field plugins generated now use attributes.
Added support for slots in the SDC generator.
Most generated plugins have been updated to use PHP attributes instead of annotations
misc:apache-virtual-host generatormisc:nginx-virtual-host generatorplugin:ckeditor generatorGenerator API is must be compatible with version 3.x
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Downgraded the required version of symfony/string to version 7.0
symfony/string to version 7.0Added compatibility with PHPUnit version 10.
Use single quotes for attribute in plugin manager generator.
Use single quotes for attribute in plugin manager generator.
The sort twig tag has been deprecated in favor of a sort_namespaces twig filter.
Before:
{% sort %}
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Utility\Random;
{% endsort %}
After:
{% apply sort_namespaces %}
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Utility\Random;
{% endapply %}
Added revision UI for generated revisionable entity type.
Plugin manager using attributes for plugins #122
Added support for Drupal 10.3
Added PhpStorm meta data for KernelTestBase methods Minor bugfixes and improvements
Added PhpStorm meta data for KernelTestBase methods Minor bugfixes and improvements
Provided a generator for single directory components
Provided a generator for single directory components (#109)
Add interactive interviewer for permissions.yml generator #106
Multiple minor bug-fixes and improvements.
DCG 3 generators are not API compatible with DCG 2, however porting them to DCG 3 is quite simple.
DCG 3 generators are not API compatible with DCG 2, however porting them to DCG 3 is quite simple.
#[Generator(
name: 'controller',
description: 'Generates a controller',
templatePath: __DIR__,
type: GeneratorType::MODULE_COMPONENT,
)]
final class Controller extends BaseGenerator {
/**
* {@inheritdoc}
*/
protected function generate(array &$vars, Assets $assets): void {
$ir = $this->createInterviewer($vars);
$vars['machine_name'] = $ir->askMachineName();
$vars['name'] = $ir->askName();
$vars['class'] = $ir->askClass(default: '{machine_name|camelize}Controller');
$vars['services'] = $ir->askServices(FALSE);
$assets->addFile('src/Controller/{class}.php', 'controller.twig');
}
}
Key differences from DCG 2 generator:
DCG 3 requires PHP 8.1+, symfony/console 6, twig/twig 3.
DCG 2 generators often created a sort of working examples, not just code templates. That has been changed in DCG 3. The generated code is now just a boilerplate, it typically does not perform any useful actions without customization. If you are looking for examples check out the Examples module.
The following generators have been removed:
Those generators had little value and were rarely used.
The phpstorm-meta generator can now provide PhpStorm with way more information about the project. It's recommended to add this command to your local deployment process and exclude the .phpstorm.meta.php directory from version control using the .gitignore file.
DCG 3 dispatches events that modules can subscribe to. Currently, the following events are available:
Note that using Drush services is still recommended way to register generators in the Drush application.
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Fixed wrong file name for post_udpate_NAME hook
Fixed wrong file name for post_udpate_NAME hook (#93)
Nothing published for this version
Added phpstorm metadata for ContainerInterface #89 Minor bug fixes
Added phpstorm metadata for ContainerInterface #89 Minor bug fixes
Nothing published for this version
Allow symfony console 6 and psr log 3 #83
Allow symfony console 6 and psr log 3 #83
Nothing published for this version
Added support for symofny/filesystem #82
Fixed compatibiltiy with Drupal 10 (#81).
Fixed compatibiltiy with Drupal 10 (#81).
Require Drupal 9 or Drupal 10 in module info file #73
Fixed rest resouce configuration in entity generator.
Fixed rest resouce configuration in entity generator.
Fixed broken composer generator.
Fixed broken composer generator.
Added entity:bundle-class command
Multiple minor bug fixes and improvements.
Multiple minor bug fixes and improvements.
Fix compatibility with Symofony 4
Fix compatibility with Symofony 4
Multiple minor bug fixes and improvements
Also, the generated code is supposed to work on Drupal 9 without triggering any deprecation notices. This means it may not be compatible with Drupal 8…
DCG 2 generators are not API compatible with DCG 1 however porting them to DCG 2 should be trivial.
Generators must extend one of the following abstract classes.
Generator
└── DrupalGenerator
├── Theme generator
└── ModuleGenerator
└── PluginGenerator
Example:
/**
* Implements controller command.
*/
final class Controller extends ModuleGenerator {
protected $name = 'controller';
protected $description = 'Generates a controller';
protected $templatePath = __DIR__;
/**
* {@inheritdoc}
*/
protected function generate(array &$vars): void {
$this->collectDefault($vars);
$vars['class'] = $this->ask('Class', '{machine_name|camelize}Controller');
$this->collectServices($vars, FALSE);
if ($this->confirm('Would you like to create a route for this controller?')) {
$vars['route_name'] = $this->ask('Route name', '{machine_name}.example');
$vars['route_path'] = $this->ask('Route path', '/{machine_name|u2h}/example');
$vars['route_title'] = $this->ask('Route title', 'Example');
$vars['route_permission'] = $this->ask('Route permission', 'access content');
$this->addFile('{machine_name}.routing.yml', 'route.twig')->appendIfExists();
}
$this->addFile('src/Controller/{class}.php', 'controller.twig');
}
}
DCG 2 requires PHP 7.3+, symfony/console 4+, twig/twig 2+ and therefore cannot be installed locally with Drupal 8.
Also, the generated code is supposed to work on Drupal 9 without triggering any deprecation notices. This means it
may not be compatible with Drupal 8. For this reason it is better to keep using DCG 1 for Drupal 8 development.
In DCG 1 generators were organized by Drupal core version. For example d7:hook, d8:hook, etc. With Drupal 9 release
it does not make much sense as the Drupal 9 API is mainly compatible with Drupal 8. So that all Drupal 8 generators
have been extracted into root namespace, i.e. d8:hook => hook. Drupal 7 generators can be found under misc:d7 namespace.
The --answer option no longer accepts JSON encoded strings. Multiple answers can be passed as follows.
dcg controller -a Foo -a foo -a FooController -a No -a No
DCG 2 is capable to generate entity types for existing modules.
$this->addFile('hello.txt')->inlineTemplate('Hello {{ name }}!');
$this->addSymlink('link.txt', 'source-file.txt');
GeneratorTester helper has been replaced with BaseGeneratorTest class. Usage example.
The command generates a completion script for DCG application.
dcg generate-completion --shell=bash >> ~/.bash_completion
When running a generator with --dry-run option the generated code will not be dumped to file system but
printed to terminal. To get information about rendered templates and collected variables enable debug verbosity (-vvv).
Generators and helpers may print messages to terminal using PSR-3 console logger.
$this->logger->debug('Example message.');
Enable verbose mode (-v) to print the information about generated assets in tabular form.
------ ---------------------------------- ------- --------
Type Path Lines Size
------ ---------------------------------- ------- --------
file example.links.action.yml 6 125
file example.links.menu.yml 11 320
file example.links.task.yml 23 630
file example.module 84 2199
file example.permissions.yml 4 83
file example.routing.yml 8 201
file src/ExampleInterface.php 15 342
file src/ExampleListBuilder.php 96 2798
file templates/example.html.twig 21 493
file src/Entity/Example.php 175 5173
file src/Form/ExampleForm.php 43 1216
file src/Form/ExampleSettingsForm.php 49 919
------ ---------------------------------- ------- --------
Total: 12 assets 535 14 KiB
------ ---------------------------------- ------- --------
When installed as local Composer package DCG is capable to bootstrap Drupal. This enables some advanced features that can improve user experience. For example, autocompletion for Drupal modules and services.
The new --destination option allows to override destination directory for dumped assets.
Improved content entity generator
generate-completion commandproject generator is now using core Composer pluginsdestination optionRemoved support for custom generators
Nothing published for this version
Nothing published for this version
Content entity and configuration entities are generated as module component Restructure name spaces of generators. D8 generators have been moved to to
Content entity and configuration entities are generated as module component Restructure name spaces of generators. D8 generators have been moved to top-level name space. Added dependency on Symfony Inflector component
Updated dependencies Added queue worker generator Cleaned legacy code
Updated dependencies Added queue worker generator Cleaned legacy code
New DCG core and updated generators.
New DCG core and updated generators.
::save() method in content entity form can call parent method #52
symfony/consoleAdded $vars parameter to ::generate method
Added phpstorm-metadata generator
full-path optionFixed https://github.com/drush-ops/drush/issues/4595
Fixed https://github.com/drush-ops/drush/issues/4595
Set up Twig environment explicitly. #46
#46 Create Twig environment explicitly #47 Alias classes only if they haven't been aliased before
#46 Create Twig environment explicitly #47 Alias classes only if they haven't been aliased before
Dropped support for PHP 5.6 and PHP 7.0
Improved compatibility with Drupal 9.
Improved compatibility with Drupal 9.
Added core_version_requirement key to info files.
Added core_version_requirement key to info files.
Fixed a bug with missing entity collection route in content entity generator.
Fixed a bug with missing entity collection route in content entity generator.
Aligned dependencies with Drupal core to avoid possible Composer conflicts.
Aligned dependencies with Drupal core to avoid possible Composer conflicts.
Nothing published for this version
Bumped minimal Twig version to work around (https://github.com/twigphp/Twig/pull/2945).
Bumped minimal Twig version to work around (https://github.com/twigphp/Twig/pull/2945).
Multiple minor bug and improvements
Fixed class name generation https://github.com/drush-ops/drush/issues/4076
Fixed class name generation https://github.com/drush-ops/drush/issues/4076
Minor bug fixes and improvements.
Minor bug fixes and improvements.
One column per quarter.