Since this module provides a form element, it seems like the next logical step should be to allow this element to be used as a widget with taxonomy term reference fields in Field API. I wrote code that can make this happen, but it's actually dependent on two other patches I just wrote to fix related issues:

There's a problem with the way the taxonomy manager tree element keeps track of its form parents in Javascript. I submitted a patch to fix this problem here: http://drupal.org/node/1222214. Without applying this patch, the form widget won't work anytime it's nested in form elements whose names contain hyphens or underscores (when you click the + to expand a term and then pick child terms, those child terms won't appear as selected in $form_state). This is a problem for Field API, because most field names have underscores in them.

There is also a problem with terms being selected when you use the form element to select single values (when it's rendered as radio buttons instead of checkboxes). This patch here allows the form element to be used with either single or unlimited-value fields, so this needs to work properly. I submitted a patch at http://drupal.org/node/1232516 to allow the radio buttons to work.

This patch alone should give you the basic Field API functionality (right now, the widget is only allowed to work with taxonomy term reference fields, with 1 value or unlimited values), but without the other two patches, you won't be able to select expanded child terms or use single-value fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nkschaefer’s picture

Title: Integrate with Field API » Integrate form element with Field API
mh86’s picture

Title: Integrate form element with Field API » Provide tree widget for term reference fields

Hi!

Such a patch definitely makes a lot of sense. I did that in Drupal 6 in combination with the Content Taxonomy module as well, and I would say that such a feature is better located in an own module. Of course, the bugs in the Taxonomy Manager need to be fixed first and I hope I'll soon find time for taking a closer look at it!

nkschaefer’s picture

All right - thanks for taking a look.

I did think having the widget in the Content Taxonomy module in Drupal 6 made sense, because there were a lot of contributed modules involved with fields/widgets/etc. -- and the Content Taxonomy module seemed like a good place to group all CCK/taxonomy-related stuff.

I guess I thought it would be a good idea to include this feature in the Taxonomy Manager module in Drupal 7, since fields are in core and term reference fields are also provided by the core Taxonomy module. The act of exposing the form element as a widget is pretty simple now - it just involves implementing a couple of hooks and making sure everything validates properly -- if there was another contrib module that provided a lot of extra taxonomy/field-related functionality, I'd think this feature would belong there, but fields are such a central concept now (i.e. you can't add taxonomy terms to nodes anymore without Field API) that I'd figured whatever module provided the Form API element should also expose it as a Field API widget.

But I respect your decision if you think it should be its own module - I just thought I should make my case here. I've also been working on another form widget that incorporates the taxonomy_manager_tree (although neither will work until those other patches are applied) - maybe I can combine those and contribute that module if/when I get it working well enough.

fuerst’s picture

You may try http://drupal.org/project/term_reference_tree which comes with a field widget performing similar to what Taxonomy Manager is providing.

marinex’s picture

@mh86 Hi can you tell me some info about it. It should be usefull for me. Thanks