Module Development

Develop Drupal Modules Faster with Drush Code Generators for Drupal 7, 8, 9, 10, and 11

Every Drupal module needs a *.info.yml file; the basic structure of a form controller class and related routing is the same for every form; and much of the code required to create a custom content entity type is boilerplate annotations and extending base classes. Wouldn't it be nice if there was a way to automate some of that repetitive work? Drush can be used to speed up module development by generating scaffolding code for event subscribers, forms, services, module files, routing, and much more. These generators are provided by the Drupal Code Generator project. They're neatly bundled up in Drush under the drush generate command.

Before Drush 9, there were no code generators in Drush, but the Drupal Console project provided them. That project and its code generators, have languished since the release of Drupal 9. While it can still be used, and is often referenced in tutorials about Drupal, we much prefer the code generated by Drush at this point.

In this tutorial we'll:

  • Learn about the Drupal Code Generator project
  • Learn how Drush integrates with this project
  • Demonstrate the drush generate command and its options

By the end of this tutorial, you'll know how to use the drush generate command to speed up development for your Drupal modules.

Command Line Tools for Drupal