This may be a self-asign, but I'll ask first in case plans are in place.

It would be very useful to add the number of available nodes in each potential selection, in a yelp-like style: for instance, how may restaurants and cafes match the current selection of city, and if restaurants are selected, how may restaurants there are in each of the available cities.

I need to hack this for a client within the next week, so wanted to ask in case there are any plans-in-place, or in case it is best to get tips about how it would be best to implement to be useful to the project.

Also, of course, as I've just +1-ed, to work with a dynamic select version of HS.

Thanks!

Comments

wim leers’s picture

There's an issue for that, and it's the oldest one in the queue: http://drupal.org/node/180691.

There's two ways:
- the proper way, which would be supporting this in Hierarchical Select itself, i.e. through an abstraction. All what would be needed per implementation is a hook that, given an item, returns the number of children (i.e. a simple COUNT() query). Via the configuration, you could then enable or disable this.
- the hacky way, which is by modifying the taxonomy implementation (modules/taxonomy.inc), and change the labels of each item, to list the number of children. The obvious disadvantage is that you'd have to repeat the same thing for every implementation of the Hierarchical Select API.

I'll go through the code today to describe more accurately how the proper way would work.

wim leers’s picture

You could do this by appending your code to _hierarchical_select_hierarchy_generate(). To get started:
- the $hierarchy object is what you want to modify. This is what dictates what will end up in the selects
- you'll want to use the hook_hierarchical_select_valid_item() hook to only retrieve the number of children for items that are really
part of your hierarchy
- you'll also want to add a new hook (hook_hierarchical_select_child_count($parent, $params)) to retrieve the number of children of a given item.

If you can provide this code *without* providing a setting to the end-user, I'll take care of that part. Let me know if you need any more information!

wim leers’s picture

Component: Code - Taxonomy » Code
Assigned: Unassigned » wim leers

patchak is sponsoring this feature. Will be implemented very soon.

wim leers’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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