A library for building Drupal code.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Environment Added better-named method getDataDirectory() to Environment; deprecat… Jul 15, 2018
Storage Added support for incremental code analysis in batches. Jul 15, 2018


Drupal Code Builder is a system for generating scaffold code for Drupal modules (and other components).

This is a library, and has no UI of its own. It can be used in several ways:

Drupal Code Builder can be used for any current version of Drupal (7, 8). Older versions are unsupported, but it should produce code for 5 and 6 also.

Tests powered by PHPUnit ensure that the generated PHP code passes PHP linting, and adheres to Drupal Coding Standards, as enforced by PHP CodeSniffer.

What Drupal Code Builder can do

Drupal Code Builder can generate the following for a module:

  • code files, containing hook implementations
  • info.yml file (.info file on Drupal 7 and older)
  • README file
  • PHPUnit test case classes, with presets for different types
  • Simpletest test case classes
  • annotated class plugins
  • YAML file plugins
  • services, with presets for tagged service types
  • content entity types, with bundle entity and base fields
  • config entity types, with properties
  • plugin types
  • theme hooks

Definitions of hooks, plugin types, and tagged service types are obtained by analyzing the current Drupal codebase of the site where the library is used. This means that Drupal Code Builder automatically knows about all hooks and plugin types from contrib and custom modules as well as those in Drupal core.

Furthermore, complex subcomponents can generate multiple code elements:

  • an admin settings form adds form builder functions and an admin permission
  • router paths add menu/router items
  • permission names add the scaffold for the permission definition


Follow the instructions given in the component that requests Drupal Coder Builder (e.g., Module Builder, Drush command).

Additionally, if Plugin module is present, plugin type definitions will be enhanced with its data.