In other issues (e.g., #784874: Add ability to insert FAPI wrapper element without modifying #parents of children), we explored the problem of modules using hook_form_alter() to alter display-only decisions. For example, CCK's fieldgroup.module uses hook_form_alter() to put fields into a fieldset. The problem with this is that anything done in hook_form_alter() affects the processing of the form, so validation and submit handlers need to be aware of whether or not fieldgroup.module is enabled. Things get even worse when similar rearrangement of elements results in the #parents property being affected (if you move things around in $form when #tree is in-use, then that affects #parents), so code that thinks it's only affecting display ends up affecting where form values are located within $form_state['values'].
In some cases, this can be solved using #pre_render. But, the problem with the way we have separated the Form API and Render API, is that during rendering, we don't have access to $form_state. The implementation of vertical tabs functionality is an example where things got convoluted because of this. Also, the goal of #591794: Allow themes to alter forms and page was to make it easier for themes to have control of forms. Most of the time, themes should only alter the display of the form, not its processing, but without a hook_form_view_alter(), they'll end up using hook_form_alter(), but without sufficient awareness of how form processing works to steer clear of changes that affect that.
The proposed hook follows the same pattern established with hook_(node|comment|user|block)_view_alter(). Once a final render array has been built, run a hook_*_view_alter() on it. Unlike the other major render arrays, we'll have both a hook_form_alter() and a hook_form_view_alter(), but that's because forms have this double identity of needing to be both processed and rendered.
| Comment | File | Size | Author |
|---|---|---|---|
| drupal.hook_form_view_alter.patch | 6.04 KB | effulgentsia |
Comments
Comment #1
rfaysubscribe
Comment #2
sunhttp://drupal.org/project/view has been secured to prevent function name clashes. (possible with and without this patch)
Comment #3
webchickOnce again, please make the case for these API changes fixing critical issues, or move them to D8.
Based on the description, I'm not sure how this qualifies, since the same situation has existed since Drupal 4.7.
Comment #4
rfayWill need a reroll after the core patch went in.
Comment #5
andypostinteresting, currently dgo.to/rel mostly works
Comment #18
smustgrave commentedWonder if this is still a valid task in D10?
Comment #20
quietone commentedIt has been nearly 2 years since @smustgrave asked if there was still a need for this to be done. The lack of response indicates there there is no need for this. Therefore, closing.
If this is incorrect, and there is a need for this, then re-open the issue and add a comment. Or open a new issue and reference this one.