Separating out form_alter functions in Drupal 7 modules
Separate out files ... reduce code loaded for most pages since main module files are loaded for every page load. Moving all code that isn't needed on every page load to different files speeds things up. Maybe. It sounds good in theory.
To make Drupal search for the default form_alter, and any other custom form, the module needs to hook_hook_info_alter().
Please note that the form validation and submit handlers don't currently work the same way and need to be included in the main module file (boooooo!) .. there should be a way around this but I haven't found it yet.
Here's some same code which offloads the default form_alter, and a specific form_alter to separate files.
function MODULE_hook_info_alter(&$hooks) { $hooks['form_alter']['group'] = 'form_alter'; $hooks['form_set_node_form_alter']['group'] = 'form_alter_set_node'; }
The associate files for these two are
MODULE.form_alter.inc MODULE.form_alter_set_node.inc