diff --git modules/hs_taxonomy.module modules/hs_taxonomy.module index 4d07f0a..c7ecb46 100644 --- modules/hs_taxonomy.module +++ modules/hs_taxonomy.module @@ -272,7 +272,7 @@ function hs_taxonomy_widget_process($element, &$form_state, $complete_form) { function hs_taxonomy_hierarchical_select_params() { $params = array( 'vid', - 'exclude_tid', // Allows a term to be excluded (necessary for the taxonomy_form_term form). + 'exclude_tid', // Allows multiple terms to be excluded (necessary for the taxonomy_form_term form). 'root_term', // Displays a fake "" term in the root level (necessary for the taxonomy_form-term form). 'entity_count_for_node_type', // Restrict the entity count to a specific node type. ); @@ -299,10 +299,14 @@ function hs_taxonomy_hierarchical_select_root_level($params) { $terms = array_merge(array($root_term), $terms); } - // Unset the term that's being excluded, if it is among the terms. + // Unset the terms that's being excluded, if it is among the terms. if (isset($params['exclude_tid'])) { + if (!is_array($params['exclude_tid'])) { + // Normalize $params['exclude_tid'] to an array. + $params['exclude_tid'] = array($params['exclude_tid']); + } foreach ($terms as $key => $term) { - if ($term->tid == $params['exclude_tid']) { + if (in_array($term->tid, $params['exclude_tid'])) { unset($terms[$key]); } } @@ -331,8 +335,15 @@ function hs_taxonomy_hierarchical_select_children($parent, $params) { $terms = taxonomy_get_children($parent, $params['vid']); - // Unset the term that's being excluded, if it is among the children. - unset($terms[$params['exclude_tid']]); + // Unset the terms that's being excluded, if it is among the children. + if (is_array($params['exclude_tid'])) { + foreach ($params['exclude_tid'] as $tid) { + unset($terms[$tid]); + } + } + else { + unset($terms[$params['exclude_tid']]); + } // If the Term Permissions module is installed, honor its settings. if (function_exists('term_permissions_allowed')) { @@ -386,10 +397,14 @@ function hs_taxonomy_get_parents_all($tid) { * Implementation of hook_hierarchical_select_valid_item(). */ function hs_taxonomy_hierarchical_select_valid_item($item, $params) { + if (isset($params['exclude_tid']) && !is_array($params['exclude_tid'])) { + // Normalize $params['exclude_tid'] to an array. + $params['exclude_tid'] = array($params['exclude_tid']); + } if (isset($params['root_term']) && $params['root_term'] && $item == 0) { return TRUE; } - else if (!is_numeric($item) || $item < 1 || (isset($params['exclude_tid']) && $item == $params['exclude_tid'])) { + else if (!is_numeric($item) || $item < 1 || (isset($params['exclude_tid']) && in_array($item, $params['exclude_tid']))) { return FALSE; } $term = taxonomy_term_load($item);