Hi there,
Implementors of systems on top of Drupal are presently unable to easily allow contrib modules to alter forms that are also altered by that core system's modules. E.g System A creates a form and a module X in its core needs to use hook_form_alter() to modify it. Contrib module M also needs to modify the bits module X put in the same form but the module name is alphabetically "less than" the core system module's name. Because module weight determines the ordering of the hook_form_alter() execution, module M will not see anything from module X because module X hasn't executed yet. We _could_ change module weights to counteract the problem. We all know that's undesired.
So here is the proposition. Add a #pre_alter to the Form API, which holds an array of functions to execute prior to the standard hook_form_alter(). This allows the system above Drupal to modify the original form after it has been populated with element_info().
I've attached a patch to add this to Drupal 7. It's not tested at this stage as it's only to illustrate what I'm talking about. If this gains traction I'll test it out.
| Comment | File | Size | Author |
|---|---|---|---|
| fapi_add_pre_alter.patch | 760 bytes | sammys |
Comments
Comment #1
moshe weitzman commentedI think module_invoke_all() needs to automatically call before/after variant hooks for every hook. lets not add more special cases.
Comment #3
catchMoving to D8.
Comment #4
valthebald@moshe weitzman comment sounds a lot like "won't fix"
Comment #18
catchYes this is won't fix. It's possible to order hooks with hook_module_implements_alter() and there's also #3485896: Hook ordering across OOP, procedural and with extra types i.e replace hook_module_implements_alter coming through.