You can also use the solution found here.
Here's an easy way to get ALL hook_form_FORM_ID_alter() implementations loaded from a .inc file, WITHOUT declaring them each separately in hook_hook_info()
.
In MY_MODULE.module add the following code.
/**
* Implements hook_hook_info_alter().
*/
function MY_MODULE_hook_info_alter(&$hooks) {
$hooks['form_alter']['group'] = 'form';
}
Then in MY_MODULE.form.inc make sure to add the following code.
/**
* Implements hook_form_alter().
*/
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
}
// Add all MY_MODULE_form_FORM_ID_alter() functions below here.
With the above MY_MODULE_form_alter()
declared in this .inc file (even if it's empty), all MY_MODULE_form_FORM_ID_alter()
implementations declared in the same file will get loaded properly. Without this function the file will not be loaded at all.
This works because drupal_prepare_form()
calls hook_form_alter()
(and loads this .inc file) before calling hook_form_FORM_ID_alter()
for each form build.
hook_hook_info()
there is not need to manually include the file.