Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I think it would be an improvement if we could specify multiple terms to exclude instead of one.
As it is today, a user can specify a single tid for the exclude_tid param, but this could easily be changed to an array to support the exclusion for multiple terms.
Comments
Comment #1
olofbokedal CreditAttribution: olofbokedal commentedComment #2
olofbokedal CreditAttribution: olofbokedal commentedOk, syntax error in the previous patch...
This should work a lot better.
Comment #3
Wim LeersWhy/when do you need this?
I'd prefer to get the D7 port complete & very stable before adding new features.
Comment #4
olofbokedal CreditAttribution: olofbokedal commentedIn my case, I needed to remove an unknown number of terms, depending on whether or not the user should be able to select them.
It doesn't change the behavior in any other way, and it still supports excluding a single term using an integer. It's not a must-have feature, but it made the module more useful to me.
I agree that a stable D7 version is more important at this moment though.
Comment #5
chrlvclaudiu CreditAttribution: chrlvclaudiu commentedHi there.
Your patch is working well, but could not be fully applied using the alpha version.
So if anyone is using the alpha and want this feature, here is the patch.
Comment #6
sabsbrain CreditAttribution: sabsbrain commentedApologies for usurping this thread - I had exactly the same requirements and created my own simple patch for the DEV version of the module a couple of days ago.
I am including it here as the patch in #5 seems to do a lot more than just fix this specific problem. I figured I'd throw my patch out here rather than open another issue.
I've checked my patch briefly and it seems to work for me - just pass an array of tids via a hook_form() function (eg ...
...['#config']['params']['exclude_tid'] = array(1,55,65,72);
If you pass in a single tid (not as an array), it should work as normal.
Hope its of use to people
Comment #7
rcodina CreditAttribution: rcodina commentedPatch on #6 works like a charm for me. I have used version 7.x-3.0-alpha12+1-dev and the patch applies ok!
Comment #8
stefan.r CreditAttribution: stefan.r commentedWhitespace
Needs a space after the comma.
Whitespace
Whitespace
Comments should end in a full stop.
Comment #9
mhmd CreditAttribution: mhmd as a volunteer and commentedAttached patch to let exclude_tid be an array so we could exclude multiple terms.
Patched against 7.x-3.0.
Comment #10
dhruveshdtripathi CreditAttribution: dhruveshdtripathi as a volunteer and at DevsAdda commentedPatch in #9 was .txt file and some of the changes were remained unchanged. So created new patch with interdiff.
Comment #11
Max_Headroom CreditAttribution: Max_Headroom commentedCan't we just insert a drupal_alter()?
Then we have more control.
I'm wondering, because I use HS in a form API and selectively want to unset some terms from the list. I'm not even sure if $params['exclude_tid'] can be set with form API (no need to answer that, I also need it to be an array anyway).
If I had to modify the code, then I'd rather just add a drupal_alter() line.
Comment #12
idiaz.ronceroHello;
When using this patch I found out that it wasn't working for excluded TIDs whenever the
element was loaded using AJAX.
I traced it down to the line 688,
function hs_taxonomy_hierarchical_select_children.
This exclusion won't work as
$terms
here is an array ofstdClass
, so it silently fails when it can't found any$terms[$excluded_tid]
(see image below).This is because taxonomy_get_tree returns "An array of all term objects in the tree"
A solution is to use the same logic the patch includes on
hs_taxonomy_hierarchical_select_root_level
, line 635:This way, it works.
The attached patch apllies this change to #10