Organizes hook_form_alter() code into separate files and adds the ability to alter forms based on a user's roles.
Moving the hook_form_alter() code into separate files makes it easier for developers to re-use their code. This module eliminates the need to create custom form altering modules for individual projects. Instead of a custom module developers can simply copy existing form_alter file code to new project and easily change it.
The ability to alter forms based on a user's roles allows developers to hide, show, or alter form elements that may or may not be needed for a specific role.
For example, an 'editor' should be able to update the general text on the 'Site information' form but they should not be able to change site configuration settings like the 'Anonymous user' and 'Default front page'.
Users with 'administer form helper alter' permission will see a 'Form helper' fieldset appended to every form. This fieldset will contain the paths to all the possible hook_alter_form() files with automatically generated sample code. To implement a hook_form_alter() a developer will need to create the specified files with the correct code.
The base hook function names and default file paths are:
| Name | Description |
|---|---|
| form_helper_alter_form_alter | Implementation of hook_form_alter(). |
| form_helper_alter_form_alter_submit | Submission handler to remove form_helper_alter_fieldset. |
| form_helper_alter_menu | Implementation of hook_menu(). |
| form_helper_alter_perm | Implementation of hook_perm(). |
| _format_helper_get_form_alter_hooks | Create and cache hooks for a form base on the $form_id |
| _form_helper_alter_append_elements_to_form | Append form helper hook paths with sample code to a form. |
| _form_helper_alter_append_form_alter_fieldset | Append hook_form_alter() fieldset with elements to a parent fieldset. |
| _form_helper_alter_execute_hook | Execute form_helper_form_alter() by loading appropriate file and executing the hook function. |
| _form_helper_alter_format_form_alter_code | Format hook_form_alter() code as an easy to edit list of array properties. |
| _form_helper_alter_format_form_alter_code_recursive | Recurse through the $form variable and create an easy to edit string. |