Releases: Chi-teck/drupal-code-generator
3.2.0
3.1.0
- Add interactive interviewer for permissions.yml generator #106
- Update drupal/coder requirement from 8.3.18 to 8.3.20 #105
- generate entity:content adds wrong permissions #102
- FileSystemInterface::prepareDirectory expects a bitmask as argument #100
- Add "drush generate readme" command #99
Multiple minor bug-fixes and improvements.
3.0.0
Release Notes
New API for generators
DCG 3 generators are not API compatible with DCG 2, however porting them to DCG 3 is quite simple.
Example of DCG 3 generator
#[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:
- Generator metadata is defined through PHP attributes.
- Most interaction logic has been moved to a separate service called "interviewer".
- All generators, regardless of their type, directly extend the BaseGenerator class.
Updated requirements
DCG 3 requires PHP 8.1+, symfony/console
6, twig/twig
3.
Revised generators
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.
Removed generators
The following generators have been removed:
- yml:theme-info
- yml:module-info
- theme:file
- misc:project
- misc:html-page
- module-file
- console:drupal-console-command
- console:drush-command
- misc:d7:* (all Drupal 7 generators)
Those generators had little value and were rarely used.
Improved PhpStorm metadata generator
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.
Event system
DCG 3 dispatches events that modules can subscribe to.
Currently, the following events are available:
- Application - allows to alter DCG application
- Generator Info - allows to register new generators
- Generator Info Alter - allows to alter registered generators
- Asset Preprocess - allows to modify generated code
Note that using Drush services is still recommended way to register generators in the Drush application.