Hello,

Is there a way to select the root term of a taxonomy_field?

For example:

I have the vocab as so:

vehicles (vocabulary)
-make and model (term)
--audi (term)
---m4 (term)
---etc (term)
-Engines
--v8

Can you select the root to be 'make and model' so that the user only sees terms under the 'make and model' term?

At the moment, the user can see all terms under the vocab vehicles.

CommentFileSizeAuthor
#3 root.png25.49 KBwim leers

Comments

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Fixed

Use a content_taxonomy CCK field instead, that supports it. HS is just a widget, it only presents data that it has been fed.

vacilando’s picture

Well, I've been thinking the last three (small!) hours and I am now sure there is a good reason to have that functionality in HS.

The reason is that some vocabularies are huge and it would be counter-productive to try to browse them from level zero.

Browsing from a deeper level is probably a solution, but a question for you / HS is where to start and set it up.

But the solution could be extremely simple -- just allow the 1st field to be a simple autocomplete (pending preferences). I am afraid I am no Ajax master but I believe swapping an Ajax select box by an Ajax autocomplete box should be a question of minutes for a Drupal ninja like you.

This would be just fantastic because the person would type a term that would autocomplete, and then s/he could complete the lineage selection with a few quick keystrokes.

Please let me know what you think; I hope you will be equally excited.

wim leers’s picture

StatusFileSize
new25.49 KB

I can see why you would want that in HS. But HS is just a widget. It should be configured in the "thing" (whether that be a CCK field or something else). That's where it belongs.
Also, I don't want to make HS any bigger than it already is.

And really, you *can* do this using a content_taxonomy CCK field. See the attached screenshot.

vacilando’s picture

Thanks, Wim!

In the meantime I've realized that I did not properly appreciate your explanation: HS is just a widget, it only presents data that it has been fed. So yes, you are correct - HS is not a CCK element, so it cannot do this.

But, unfortunately, the solution you have suggested for selection of the root term is not a satisfactory because I need to set a different root term on each page! That is why I need to be able to autocomplete type it.

Any final ideas on this?

Tomáš

wim leers’s picture

Why do you need it to be different on each page? Then you would also have a boatload of config forms to go through. So in that case, it would be much better to write your own implementation of HS. You'd only have to implement the _root_level() hook and the rest of the hooks would be simply aliases of the taxonomy implementation.
You'll only be able to do this if you're a developer though.

wim leers’s picture

To show you how little you'd have to change, it'd only be this:

function taxonomy_hierarchical_select_root_level($params) {
  $terms = _taxonomy_hierarchical_select_get_tree($params['vid'], 0, -1, 1);
  return _taxonomy_hierarchical_select_terms_to_options($terms);
}

to:

function YOURMODULE_hierarchical_select_root_level($params) {
  $terms = _taxonomy_hierarchical_select_get_tree($params['vid'], $params['root_tid'], -1, 1);
  return _taxonomy_hierarchical_select_terms_to_options($terms);
}

And add another "param" to the required parameters called root_tid.

wim leers’s picture

This just made me realize that I'm not yet supporting this at all in the content_taxonomy implementation! I've never had complaints about it because … nobody uses it.

EDIT: created an issue for this: http://drupal.org/node/276041. Note that this means you'll be able to simply use the content_taxonomy implementation, all you will have to do is define the form using the Forms API.

vacilando’s picture

That seems rather simple and I should be able to do this. OK, so I'll watch the other thread - hope it will not take too much work for you to fix that. Thanks for your excellent work!

wim leers’s picture

Done! Check the other thread ;) :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.