[development] Overiding #theme in hook_form_alter()
Barry Jaspan
barry at jaspan.org
Fri Jun 16 13:01:21 UTC 2006
I've written the module that wants to override the #theme of another
module's form. I discovered that in hook_form_alter I cannot set the
#theme field because drupal_get_form overrides #theme after calling
hook_form_alter it if the function theme_<formname> exists or the
$callback argument is provided.
This seems like an unintentional restriction to me. Is
it? Hook_form_alter can change everything else about a form, so why
should it not be able to change the #theme field? I know the theme
function can be overridden by the site theme but that forces the
module not to be self-contained.
The workaround I found is to add a callback to the form's #pre_render
array that sets the form's #theme field. This works fine (because
#pre_render is invoked after drupal_get_form overrides #theme) but is
certainly not intuitive; if this really is the best way to do it,
I'll author a new page for the Forms API Tips and Tricks book section.
Thanks,
Barry
Note: This message was dictated using voice recognition
software. Please excuse any errors I missed.
More information about the development
mailing list