Support from Acquia helps fund testing for Drupal Acquia logo

Comments

olofbokedal’s picture

Status: Active » Needs review
FileSize
2.89 KB
olofbokedal’s picture

Ok, syntax error in the previous patch...

This should work a lot better.

Wim Leers’s picture

Status: Needs review » Postponed (maintainer needs more info)

Why/when do you need this?

I'd prefer to get the D7 port complete & very stable before adding new features.

olofbokedal’s picture

In 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.

chrlvclaudiu’s picture

Hi 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.

sabsbrain’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.99 KB

Apologies 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

rcodina’s picture

Issue summary: View changes

Patch on #6 works like a charm for me. I have used version 7.x-3.0-alpha12+1-dev and the patch applies ok!

stefan.r’s picture

Status: Needs review » Needs work
  1. +++ b/modules/hs_taxonomy.module
    @@ -580,8 +580,14 @@ function hs_taxonomy_hierarchical_select_root_level($params) {
    +    ¶
    

    Whitespace

  2. +++ b/modules/hs_taxonomy.module
    @@ -580,8 +580,14 @@ function hs_taxonomy_hierarchical_select_root_level($params) {
    +      // Check if the term is in our array of exclusions
    +      if (in_array($term->tid, $params['exclude_tid'])) {
             unset($terms[$key]);
           }
    
    @@ -670,8 +683,15 @@ function hs_taxonomy_hierarchical_select_valid_item($item, $params) {
    +      $params['exclude_tid'] = array($params['exclude_tid']);
    +    }
    +  }
    ...
    +  if (!is_numeric($item) || $item < 1 || (isset($params['exclude_tid']) && in_array($item,$params['exclude_tid']))) {
    

    Needs a space after the comma.

  3. +++ b/modules/hs_taxonomy.module
    @@ -612,7 +618,14 @@ function hs_taxonomy_hierarchical_select_children($parent, $params) {
    +    ¶
    

    Whitespace

  4. +++ b/modules/hs_taxonomy.module
    @@ -670,8 +683,15 @@ function hs_taxonomy_hierarchical_select_valid_item($item, $params) {
    +  ¶
    

    Whitespace

  5. +++ b/modules/hs_taxonomy.module
    @@ -670,8 +683,15 @@ function hs_taxonomy_hierarchical_select_valid_item($item, $params) {
    +  // Ensure exclusion is an array
    

    Comments should end in a full stop.

mhmd’s picture

FileSize
1.31 KB

Attached patch to let exclude_tid be an array so we could exclude multiple terms.

Patched against 7.x-3.0.

dhruveshdtripathi’s picture

Patch in #9 was .txt file and some of the changes were remained unchanged. So created new patch with interdiff.

Max_Headroom’s picture

Can'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.

idiaz.roncero’s picture

Hello;

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.

    foreach ($params['exclude_tid'] as $excluded_tid) {
      unset($terms[$excluded_tid]);
    }

This exclusion won't work as $terms here is an array of stdClass, 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"

The array structure

A solution is to use the same logic the patch includes on hs_taxonomy_hierarchical_select_root_level, line 635:

    foreach ($terms as $key => $term) {
      // Check if the term is in our array of exclusions
      if (in_array($term->tid, $params['exclude_tid'])) {
        unset($terms[$key]);
      }
    }

This way, it works.

The attached patch apllies this change to #10