Hi there,
I notice the code has the ability to restrict terms to a node type via a '$type' parameter ( hs_taxonomy_term_count_nodes )
However, that type parameter isn't passed by hs_taxonomy in it's hook_hierarchical_select_entity_count.
Restricting entity count by node type is very useful, particularly for custom forms using hs_select with a shared vocabulary.
The attached patch allows restricting by node type.
Example
<?php
// note the 'node_type' option in 'params'
$form['location'] = array(
'#type' => 'hierarchical_select',
// Consult API.txt for an explanation of all these settings.
'#config' => array(
'module' => 'hs_taxonomy',
'params' => array(
'vid' => $location_vid, // Enter your vocabulary ID here.
'root_term' => NULL, // Enter a term ID here if you want to display only terms below the term with that ID.
'node_type' => 'agent', // PATCH: restrict to type for entity count
),
'save_lineage' => 0,
'enforce_deepest' => 0,
'entity_count' => 1,
'require_entity' => 1,
'resizable' => 0,
'level_labels' => array(
'status' => 1,
'labels' => array(
0 => t('Location...'),
1 => t('Town/City...'),
2 => t('Suburb...'),
),
),
'dropbox' => array(
// Only allow for a single term or single lineage to be selected.
'status' => 0,
),
'editability' => array(
// Creating new terms from within a form to filter by existing terms
// doesn't make sense, hence it is disabled.
'status' => 0,
),
),
'#default_value' => isset($defaults[$location_vid]) ? array($defaults[$location_vid]) : array(), // To set a default value, fill this with one or more term IDs.
);
?>
| Comment | File | Size | Author |
|---|---|---|---|
| hs_taxonomy.module.patch | 596 bytes | davidwhthomas |
Comments
Comment #1
davidwhthomas commentedComment #2
wim leersExcellent addition :)
I made a few minor changes to comply with Drupal coding standards. I also added it to a few other places for the sake of completeness and documented it in the code.
Committed!
http://drupal.org/cvs?commit=495030
Comment #4
davidwhthomas commentedThanks!
Just an update, the committed patch requires
'entity_count_for_node_type' as opposed to 'node_type'
The inital patch and example used the latter.
New patch tested and working in current release.
cheers,
DT
Comment #5
sovarn commentedI must be really stupid, but where is this option to only restrict the count to a certain node type?
I have looked in the "edit vocab" page and all the HS settings page, but I can't seem to find it. :S