[support] how to Form Render-Alter in D7?

Carl Wiedemann carl.wiedemann at gmail.com
Tue Oct 11 14:18:22 UTC 2011


I've never heard of THEME_form_hook_alter().

template.php is generally for theme override functions. That is, the
functions in this file will be overriding the output of existing theme
functions which are defined by hook_theme.

Drupal themes only serve to rewrite existing output. All original output in
Drupal is defined by theme functions, which appear modules. The stark theme
is a nice working example of this -- notice that there are no included
templates. Markup starts with modules.

In your case, you have only defined the override, not the originating theme
function. So, in your module, you need to so something like the following:
http://pastebin.com/vkXbxeX7

This will require a cache clear such that the theme registry will now know
about hook_theme().

Carl Wiedemann
Website design and development consulting
carl.wiedemann at gmail.com | skype: c4rlww



On Mon, Oct 10, 2011 at 11:34 PM, sebastian <inforazor at gmail.com> wrote:

> Hello,
>
> Very sorry to ask this, but I am going in a loop with the documentation,
> and the IRC chat isn't helping much either... so I hope this won't take
> much of your time.
>
> I understand in D7 that we can write in a custom module for form
> alterations such as:
>
> file: webadmin_ui.module
> //this is a custom module I made
>
> function webadmin_ui_form_page_node_form_alter(&$form, &$form_state,
> $form_id) {
>        dpm ($form);//see values
>        //change values as you please here...
> }
>
> And I also understand that in D7 we REMOVED the feature/function to
> alter the form values in the THEME layer, so this function was killed:
>
> THEME_form_hook_alter($form) {}
>
> Because supposedly I can theme it via different methods.
>
> In the $form variable, when I DPM it [see above] I note the theme-chain:
>
> dpm($form) outputs: [among other things]
>
> $form['#theme']['page_node_form']
> $form['#theme']['node_form']
>
> If I try and be "smart" and write in my template.php:
>
> mytheme_page_node_form($form) {
>  dpm("it works!");
> }
>
> I clearly get nothing as this function is never called.
>
> Can I add my own function call to this list? If so, how?
>
> Is there documentation on this anywhere?
>
> The documentation in D6 was a mess, and for this in D7 its really no
> better [maybe even worse cause I keep hitting D6 pages mixed into D7
> ones with no warning].
>
> The whole point of all this is I want to understand how I can not only
> modify the form BEFORE it gets rendered, but also alter HOW the form is
> rendered... wrap some parts in a DIV, maybe add a missing CLASS or ID etc.
>
> Ideas?
>
> Thank you kindly,
>
> Sebastian.
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20111011/a534443b/attachment.html 


More information about the support mailing list