Generators jump start your coding by building all the boring boilerplate code for you. After running the generate command, you have a guide for where to insert your custom logic.
Writing Custom Generators¶
Drupal modules may supply their own Generators, just like they can supply Commands.
See Woot module, which Drush uses for testing. Specifically,
- Write a class similar to ExampleGenerator. Implement your custom logic in the interact() method. Typically this class is placed in the src/Generators directory.
- Add a .twig file to the same directory. This template specifies what gets output from the generator.
- Add your class to your module's drush.services.yml file (example). Use the tag
- Perform a
drush cache-rebuildto compile your drush.services.yml changes into the Drupal container.
Generators that don't ship inside Drupal modules are called global generators. In general, it is better to use modules to carry your generators. If you still prefer using a global generator, please note:
- The file's namespace should be
- The filename must have a name like Generators/FooGenerator.php
- The prefix
Foocan be whatever string you want. The file must end in
- The enclosing directory must be named
- The prefix
- The directory above Generators must be one of:
- A Folder listed in the --include option. include may be provided via config or via CLI.
/sites/all/drush. These paths are relative to Drupal root.