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.
  );
?>
CommentFileSizeAuthor
hs_taxonomy.module.patch596 bytesdavidwhthomas
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidwhthomas’s picture

Status: Active » Needs review
Wim Leers’s picture

Title: Patch to allow passing node type to restrict entity count » Allow passing node type to restrict entity count
Status: Needs review » Fixed

Excellent 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

Status: Fixed » Closed (fixed)

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

davidwhthomas’s picture

Thanks!

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

sovarn’s picture

I 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