Add hook_form_view_alter()

Created on 13 May 2010, about 15 years ago
Updated 23 June 2023, about 2 years ago

In other issues (e.g., πŸ“Œ Add ability to insert FAPI wrapper element without modifying #parents of children Needs work ), 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.

πŸ“Œ Task
Status

Postponed: needs info

Version

9.5

Component
FormΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States effulgentsia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Wonder if this is still a valid task in D10?

  • Status changed to Closed: works as designed 2 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    It 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.

Production build 0.71.5 2024