Animal Filter for Breed/Species based on Taxonomy Hierarchy?

The filter at the top of the animal asset screen (Records → Assets → Animal) includes a field for Species/breed. I have setup my Taxonomy to have the species (like Chicken) with breeds under the species, like this:


What I have noticed is that when I select “Chicken” in the species/breed filter field, it doesn’t show any animal assets since no animals are actually listed as simply “chicken” but instead their actual breed. I have to select each “leaf” term individually.

I would like the filter to include any the lower level taxonomy terms. I currently have 13 different species of chickens on my farm, so it would be much easier for me to see all my chickens if I could just select “Chicken” and have it display every species that is under the Chicken hierarchy.

2 Likes

I agree this is a gap and would be a great feature. I’ve run into this many times myself - with rabbit breeds and plant type terms in my case.

1 Like

Yea this has come up before - I agree! It’s a shame that Drupal’s default Views filter handler for terms doesn’t offer that option out of the box (we’re just using the functionality that comes with Drupal for this).

I did a quick search and found this:

Might be possible to implement in the farm_ui_views module (which provides the default farm_asset Views).

I suppose it’s worth posing the question: are there cases where you would NOT want it to work this way? Because if we make this change, it essentially removes the ability to filter down to assets that ONLY have the parent term.

Ah wait… looking closer… that link is not exactly what we want. But it might still be helpful to study how that works and devise our own method.

One other thought… another way to achieve the desired filtering might be to simply reference multiple terms on the same asset. For example, tag the animal asset with BOTH “Chicken” AND “Barred Rock” terms. This essentially uses a data convention to achieve the desired functionality instead of a technical solution.

Unfortunately, that isn’t currently possible with Animal assets, because they only allow a single “Animal type” term to be referenced. Other asset types like Plant allow multiple. So we could consider changing Animal assets to allow multiple as well.

Not suggesting this is the right solution, just adding it as one to consider. :slight_smile:

From a technical implementation standpoint, in order to filter by all child terms, we would need need to load the IDs of all child terms and include those in the SQL WHERE condition.

1 Like

I was assuming it should be a checkbox next to the term type dropdown.

1 Like

Found this, which points to an existing option in Drupal core “Has taxonomy terms (with depth)”:

However, that only works for nodes, not other entities types (like assets). Apparently this contrib module adds the same filter for other entity types: https://www.drupal.org/project/taxonomy_entity_index

As I understand it the “Has taxonomy terms (with depth)” would allow us to say “include child terms up to N levels deep” in the filter configuration.

AFAIK the “Has taxonomy terms (with depth)” filter does not provide that option. But it’s worth trying it out in a local environment to see what it does/doesn’t do and report back here. Perhaps we could extend it just slightly in our own custom handler to add that checkbox you described @Symbioquine.

1 Like