By pwolanin on
I'm trying to use hook_form_alter to wrap each of the selects in the taxonomy part of the node form with a div. Can someone explain to me why the code below doesn't work?? It does work to add an attribute to the form element, etc. However, the code referencing the #prefix and #suffix parts of the form element seem to have no effect on the HTML output. Is this a bug?
function zmod_form_alter($form_id, &$form) {
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
foreach(element_children($form['taxonomy']) as $key) {
$form['taxonomy'][$key]['#prefix'] = '<div class = "taxonomy">';
$form['taxonomy'][$key]['#suffix'] = '</div>';
}
}
}
Comments
...
That's because these SELECTs have a #theme handler that causes the #prefix and #suffix to be ignored.
You're supposed to override theme_taxonomy_term_select to theme these SELECTs. Alternatively,
unset($form['taxonomy'][$key]['#theme']).Also, check http://drupal.org/node/60797
Thanks for the pointers- am
Thanks for the pointers- am I just dense, or should the Forms API docs be updated to mention that #prefix and #suffix are discarded if a theme function is defined?
-Peter
---
Work: BioRAFT
...
I don't know that. And I can't tell you whether that was a bug or not. Maybe it just depends on your world-view...
I've just found two relevant docs:
Make taxonomy selection widget themable (issue)
Select Taxonomy terms as checkboxes and radio buttons! (forum)
seems to be a "feature"
Tis seems to be a "feature" in as much as I can see clearly where it happens in the form_render code. I guess the idea is that any custom theme function should either use the prefix/suffix or will have some other/custom markup.
I think I could calssify this as a bug in theme_taxonomy_term_select, and maybe I'll submit an issue, since this theme function bears responsibility for using the prefix/suffix.
---
Work: BioRAFT