Last updated January 3, 2012. Created by LeeHunter on January 2, 2008.
Edited by tony31, joachim, seanr, pwolanin. Log in to edit this page.
Module builder can significantly speed up your development of new and existing modules by generating your .info and .module files, complete with template functions for hook implementations.
It can be installed as regular Drupal module, and provides an admin interface to let you pick the hooks you want.
It also provides a Drush command, which writes the files you generate directly to their final location, ready to be enabled.
Features
- Automatically parses available hook names from CVS at your command... so help keep those files updated, won't you? ;)
- Comes with some sample standard hook function declarations to get you started and a default module header; but if you don't like those, simply rename the .template files to -custom.template instead and create your own definitions!
- Saves you the trouble of looking at drupaldocs.org 50 times a day to remember what arguments and what order different hooks use. Score one for laziness! ;)
- Automatically selects hooks based on your needs.
- Option allows you to turn off informative comments.
Installation and Configuration: Drupal
- Move this folder into your modules/ directory like you would any other module.
- Enable it from administer >> modules.
- Go to administer >> settings >> module_builder and specify the path to save the hook documentation files
- The first time you visit the module builder form, the module will retrieve hook documentation from cvs.drupal.org and store it locally. When you want to update this documentation later on, return to the settings page and click the "Update" button.
- (Optional) Create custom function declaration template file(s) if you don't like the default output.
- (Optional) Create your own hook groupings if you don't like the default ones.
Installation and Configuration: Drush
Move this folder to somewhere where Drush can find the command. The prefered location is in a folder called .drush your HOME folder (i.e. ~/.drush/module_builder). Inside drush/commands will also work, though then you have to watch you don't clobber it on upgrade. Drush documentation has details on other options.
From a Drupal installation, do:
$ drush mbdlThis will download hook files to Drupal's files/hooks folder. Hooks are downloaded for core and any other module builder-aware modules that are in this install of Drupal.
To download do a different location, do:
$ drush mbdl --data=/home/ME/DIRThe directory should already exist.
You should then use the --data option for subsequent module builder commands. This means you use a central store of hook data for all your Drupal sites. Whatever hook files are already there will be overwritten, but this way you can accumulate hook files for modules present in only some of your installations. The hook data is processed each time files are downloaded, so all hook files are included.
Using The Module on Drupal
- Click the "module_builder" link in the menu (note: you will require 'access module builder' privileges to see this link).
- Enter a module name, description, and so on.
- Select from one of the available hook groupings to automatically select hook choices for you, or expand the fieldsets and choose hooks individually.
- Click the "Submit" button and watch your module's code generated before your eyes! ;)
- Copy and paste the code into a files called .module, .info and .install and save them to a directory under one of the modules directories.
- Start customizing it to your needs; most of the tedious work is already done for you! ;)
Drush commands
Example commands:
drush hooks List all available hooks and their descriptions.
drush mb my_module menu cron nodeapiGenerate module code with hook_menu, hook_cron, hook_nodeapi. This is the simplest way to run module builder. --build=code is assumed.
drush mb my_module --name="My module" --dep="forum views" --build=infoGenerate an info file with readable name and dependencies.
drush mb my_module cron --name="My module" --dep="forum views" --write Generate both module and info files, write files to sites/all/modules and also output to terminal. The --write option assumes you want --build=both. Add --quiet if you don't want terminal output. Add --yes to clobber existing files without being asked.
drush mb my_module nodeapi form_alter --addAppend hooks to the existing module file.
drush dochooks my_module Add PHPDoc headers to all hooks (that don't have any) in the given module.
Telling module builder about your hooks
Lots of contrib modules provide hooks. You can tell module builder about them, so users can easily generate code for your module's hooks in their own modules.
To do this, implement hook_module_builder_info() in a file named YOUR_MODULE.module_builder.inc file in your module folder. See the contents of module_builder.module_builder.inc for a detailed example.
Comments
Is the hooks command not
Is the
hookscommand not changed tomb-list?I think you're right.
I think you're right.
--
Solar Mosaic supports Drupal
I followed the directions
I followed the directions of:
Installation and Configuration: Drupal
I installed the module, went to the settings page and left the default values;
Path to hook documentation directory: hooks
verified the folder had been created in the directory:
sites/default/files/hooks
then per step 4 went to the admin/build/module_builder and got this error message:
"No hooks were found. Please check the documentation path specified in the Administer >> Site configuration >> Module builder page."
I tried the update hooks button: admin/settings/module_builder/update and it resulted in a blank page.
Could someone tell me what I've done wrong?
Thanks.
Same with me
Same with me
Same here. Did you ever fix
Same here. Did you ever fix the problem ?
No hooks were found. Please check the documentation path specified in the Administer >> Site configuration >> Module builder page
The download tab does fetch a bunch of hooks documentation though. Don't know why nothing else works.
Automatic Download gets 404
Tried to use the automatic download function, but it only saves files as 404 errors. That's why others are having issues.
Errors when installed in drush/commands/ directory
Just to let people with the same problem know ... (this page was the first hit in my search)
I installed module_builder in my drush/commands/ directory in a Drupal 6.4 (I know, I know ... upgrade ...) installation. I kept getting the following error when running drush mb-download:
Invalid argument supplied for foreach() module_builder.drush.inc:670... and I would get the following error when running mb-build:
Invalid argument supplied for foreach() process.inc:22 [warning]PHP Fatal error: Unsupported operand types in /opt/drush/commands/module_builder/includes/generate.inc on line 390
Drush command terminated abnormally due to an unrecoverable error.
I trashed the drush/commands/module_builder/ directory and installed module_builder into sites/all/modules/ and enabled the module. Both errors when away.