Skip to content

Releases: Chi-teck/drupal-code-generator

2.2.0

15 Oct 16:10
Compare
Choose a tag to compare

Multiple minor bug fixes and improvements.

2.1.1

10 Oct 10:23
Compare
Choose a tag to compare

Fix compatibility with Symofony 4

2.1.0

10 Oct 09:21
Compare
Choose a tag to compare
  • Added support for PHP 8.1
  • Dropped support for PHP 7.3
  • Multiple minor bug fixes and improvements

1.33.1

05 Dec 13:46
Compare
Choose a tag to compare

2.0.0

21 Oct 09:33
Compare
Choose a tag to compare

Release notes

New API for generators

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');
  }

}

Updated requirements

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.

Generator namespaces have been changed

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.

Answer option now accepts multiple values

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

Improved entity type generators

DCG 2 is capable to generate entity types for existing modules.

Added support for inline templates.

$this->addFile('hello.txt')->inlineTemplate('Hello {{ name }}!');

Added support for symlinks.

$this->addSymlink('link.txt', 'source-file.txt');

New base class for generator tests

GeneratorTester helper has been replaced with BaseGeneratorTest class. Usage example.

New generate completion command

The command generates a completion script for DCG application.
dcg generate-completion --shell=bash >> ~/.bash_completion

Dry run mode

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).

PSR-3 logger

Generators and helpers may print messages to terminal using PSR-3 console logger.

$this->logger->debug('Example message.');

Extended result printer

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  
 ------ ---------------------------------- ------- -------- 

Drupal context

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.

Destination option

The new --destination option allows to override destination directory for dumped assets.

2.0.0-RC3

14 Oct 08:06
Compare
Choose a tag to compare
  • Added Label interface
  • Updated symfony/console
  • Removed Logger factory
  • Updated D9 hook templates
  • Updated D9 service definitions
  • ::save() method in content entity form can call parent method #52

1.33.0

11 Oct 17:07
Compare
Choose a tag to compare
  • Set up Twig environment explicitly. #46
  • Addded menu link for module settings form. #55
  • Resolved deprecations.

2.0.0-RC2

25 Jul 10:12
Compare
Choose a tag to compare
  • Added $vars parameter to ::generate method
  • Fixed minor bugs in field generator
  • Changed choice question prompt
  • Added base class for testing generators
  • Added Drupal package types to composer.json generator (#49)
  • Removed references to Drupal 8 (#50)
  • Added PHAR compile script

1.32.1

15 Jul 06:32
Compare
Choose a tag to compare

#46 Create Twig environment explicitly
#47 Alias classes only if they haven't been aliased before

2.0.0-RC1

29 Jun 11:09
Compare
Choose a tag to compare
  • Added phpstorm-metadata generator
  • Add full-path option
  • Renamed entity administer permissions (#44)
  • Multiple minor improvements in content-entity generator