Scenario

On a multilingual site, I need to show a list of vocabulary terms, not in text but all terms replaced by their respective image links.

What I did

  1. Created custom image field for the vocabulary
  2. Created a view that shows the taxonomy name and image
  3. Created block for the view which I can insert on wanted page

What I got

I got the term name with image but I'm unable to make the image refer to the taxonomy link. In the views, there is an option to Link to the taxonomy term, that generates language specific taxonomy URL but its available only for the name field of the term.

What else I tried

I tried getting taxonomy terms programatically using \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadChildren('VOCABULARY_ID'); (loadTerm was not giving full object detail even after I tried TRUE as the last param. Rather it gave error.). I do get the terms but can't figure out how to get language specific URLs. If I can get language specific URL as pet the node language, I can code the image such that it gets the URL and taxonomy name for ARIA accessibility purpose.

So what I need

Either of these

  • A way to add Link to the taxonomy term option for image field in views settings dialog
  • A way to get node language specific URL of the taxonomy term programatically
  • Any other magical solution you can come up with

Ofcourse, using JS I can make all the content within the taxonomy term clickable with to the taxonomy link, but I prefer to use server processing than client side.

Thankyou

Comments

Jeff Burnz’s picture

It's a bit hard to understand what you are asking about here.

When you create a view of fields you can link the image field to content (the taxonomy term page, e.g. ~/taxonomy/term/2), isn't this what you want?

panchtatvam’s picture

Yeah I want to do that but, "link to taxonomy term" option is not available for image field in a view.

Jeff Burnz’s picture

panchtatvam’s picture

Content does allow me to add the custom image field but doesn't allow to wrap taxonomy link anchor around it. So what I get is just an image for the taxonomy which can't be clicked.

Jeff Burnz’s picture

All you do is create a View of Taxonomy Terms (fields), as block, remove the title field that is added by default, then add the term image field, edit that field and select the option to link to content. Done.

Taxonomy terms are entities, therefor the option of "content" makes perfect sense - in this case the content being the taxonomy term page listing all items marked with a particular term.

panchtatvam’s picture

I was so confused due to that "Link to taxonomy term" option. Thanks to you, I was able to understand "content" will work just fine. I used "Link to"->"Content" and it just works. Thanks again :D