Score:1

Add additional taxonomy term fields to an exposed filter form

in flag

Brief: How to add a custom field from a taxonomy term into a View's exposed filter form?

Specific: I have an image field added to taxonomy terms that I want to add to the exposed filter form along with the radio button and the TID's name (default is only radio + name), themed with Twig template.

More words:
Hello,
I'd like to modify an exposed Views filter form to include the rendered image field from the taxonomy terms listed in the exposed filter. I've run into several dead ends getting this to work in Drupal 9.x. Some of the instructions I've found seem to be either for older versions, or I'm just unable to sort this out.

My View is set up to have "Content: Has taxonomy term ID" contextual filter, with the appropriate settings for the filter criteria. Everything works great for the exposed filter on the target page.

The term itself has the added field of a Media image, which works fine when visiting the term's page, for instance.

I've tried many different things, but most recently I am using the Better Exposed Filters module, with the results displayed as "inline" and I have a Twig template that overrides the output (/templates/views/views-exposed-form--[view-name]--[display-name].html.twig), which does work.

I'm stuck getting any access to the actual custom field from the taxonomy term! I can access everything from the base TID & name, etc., but I can't figure out how to get at the extra field so I can try to render it in the Twig template.

Stuff I tried and/or don't understand:

I'd prefer to do this purely in Twig templates (unless that's dumb?), but I also will do a simple module with a hook_form_alter if it is better... I'm admittedly new to Drupal 8/9 (I'm trying to migrate an old Drupal 7 site), so I figure I'm missing some things here.

THANK YOU for any help/ideas making this ugly form look purty!!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.