Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Drush Code Generator Example

No security coverage Under active development

This module provides a step-by-step guide and examples for developers on how to create custom Drush generate commands. It demonstrates how to use Drush's code generation capabilities to create boilerplate code based on user input, allowing for custom templates and workflows.

This is an example module, explaining step by step how you can create
your own drush generate command.

Workings with drush 10.x

Do not enable this module in production environment!

Example:

drush generate gnform

BACKGROUND:

---------------------

This module was inspired by Louis Nagtegaal - article and Jacob Rockowitz - module.

As Louis mentioned in his article:

For Drupal site builders, drush is the Swiss army knife that can be used for a wide range of purposes, from simply clearing the cache to updating translations or even installing a complete new site.

In the more recent versions of drush, a command was added that makes drush also interesting for Drupal developers.
This command, generate, makes it easy to generate boilerplate code for modules, plugins, services and much more.
And it is even possible to extend existing custom (or contrib) modules with a generator.

The generate command use chi-teck/drupal-code-generator-library.

What I really like about the Drush Generate command is that it allows you to generate specific templates based on user answers, those questions usually include the machine name of the module you want to add the code to, the machine name of the plugin that is created, which services you want to inject or which routes you want to add, etc...

After some research and due to the lack of documentation on how to create your own drush generate command, I decided to create a custom module explaining in detail how you can generate your custom code using the drush generate feature.

I will use Examples for Developers module as an example.

GOAL

------------
Developers can learn how to generate custom blueprint templates
by experimenting with those examples, and adapt them for their own use.

How can you help?

------------------
I'm glad you asked:

Most of all, we need you to file an issue every time you find an error or ambiguity or something that could be presented better.
* We need additional examples.
* We need reviews, corrections, and improvements to existing code.
* We need improvements in the documentation.

Drupal 8–9 · not 10, 11

Ask your assistant about Drush Code Generator Example

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.

Activity

Tracked releases
6
Tracked since
Jun 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Release Timeline

Releases

Version Type Core PHP Release date
1.0.3 Stable 8–9 Jun 30, 2023
2.0.x-dev Dev 8–9 Jun 30, 2023
1.0.x-dev Dev 8–9 Jun 28, 2023
1.0.2 Stable 8–9 Jun 28, 2023
1.0.1 Stable 8–9 Jun 28, 2023
1.0.0 Stable Jun 28, 2023