2

I have a lot of different vocabularies. On The taxonomy page (the standard view provided) I would like to add a block (view) that takes the current taxonomy id from the url/page and displays all taxonomy terms belonging to the same vocabulary. I tried adding a contextual filter, but when I choose term id from url, the view only shows one term, but I would like to show all terms of the vocabulary the term belongs to.

Of course I could create a block for each vocabulary, but as I have a lot, I'm searching for a more dynamic approach.

For Example: on the page /taxonomy/term/39 I would like to add a block (view) that takes the taxonomy id 39 and lists all terms of the vocabulary the id 39 belongs to.

4
  • Welcome to Drupal Answers! You should provide more context for this question, e.g. your views configuration, so that users here can better understand your problem.
    – berliner
    Commented Nov 8, 2021 at 13:09
  • From the top of my head, I'd say you also need a relationship to the parent vocabulary in order to pull in other terms. But it's a bit difficult to say without seeing your views configuration.
    – berliner
    Commented Nov 8, 2021 at 13:13
  • I tried to clarify and edited my question
    – Mike
    Commented Nov 8, 2021 at 16:40
  • I just played a bit around with views and it seems to me that you can't do what you want with Drupal core. There is no option to add a relationship from a term to a vocabulary and no option either to retrieve the vocabulary from the current term page. So either there is a contrib module that solves this that I couldn't find, or you need to do some custom coding to achieve this.
    – berliner
    Commented Nov 8, 2021 at 18:32

1 Answer 1

1

I created a views argument_default plugin that did the trick:

public function getArgument() {
  if (($taxonomy_term = $this->routeMatch->getParameter('taxonomy_term')) && $taxonomy_term instanceof TermInterface) {
    $vocabulary = $taxonomy_term->bundle();
    return $vocabulary;
  }
}
1
  • Nice! Glad you found a solution.
    – berliner
    Commented Nov 8, 2021 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.