0

I found similar questions but not an actual answer... This is my setup In Drupal 8:

Node

Paragraph

Taxonomy term reference

I would like to use the default taxonomy term view (taxonomy/term/%) to display a list of node teasers in which the paragraph contains the term. I'm probably passing the wrong contextual filter but I couldn't figure how to fix it. Default taxonomy term view override

6
  • Ok well I don't think you should use the default taxonomy term view, because look at the filter critera "taxonom term publish" can you create a new view of node content of type all or your content type make a page and give it a path as default taxonomy view starts from the taxonomy table not the node table. Really this would be way easier if you started form scratch but if you really wanted to use the path "taxonomy/term/%" thats fine just disable the current view see if that helps and update your question.
    – taggartJ
    Commented Feb 5, 2018 at 3:09
  • Thanks for the anwser my friend, but: - The filter criteria is not filtering anything since all terms are published (or whatever it means). I tried using the same vocab for a simple node with a term and it displays. - Disabling the view simply displays nothing. After restoring the original view, it does not display the nodes with the term in the paragraph (it does show the simpler ones) I'm trying to rebuild the view as you said now...
    – Elgandoz
    Commented Feb 5, 2018 at 8:37
  • ...and you were right, starting from scratch, and keeping the exact same configuration works! Not sure why I didn't think it before. Thanks!!
    – Elgandoz
    Commented Feb 5, 2018 at 9:04
  • Unfortunately in this way, I'm not able to display the term title... in the contextual filter settings I tick the checkbox "override title" and insert the replacement pattern from below "{{ arguments.field_brand_target_id }} == Paragraph: Brand (field_brand) title" but the page title it's the raw tid...
    – Elgandoz
    Commented Feb 5, 2018 at 9:38
  • the not sure "Not sure why" is because how views structures its quries So What you select when you first create you view will Set some things in the views base query, so in your case it was stuck on the term table easy to go from node -> Paragraph -> entity ref taxonomy term.
    – taggartJ
    Commented Feb 6, 2018 at 0:06

2 Answers 2

0

As per you comments you need some thing like the following to change the Title to a taxonomy term.

/**
 * Implements hook_views_pre_render().
 */
function MODULE_views_pre_render(Drupal\views\ViewExecutable $view) {
  // Get the machine name of your view and replace below.
  if ($view->id() === 'myview_machine_name') {
    $tid = $view->args[0];
    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
    // overide the title with the term name.
    if (is_object($term)) {
      $view->build_info['title'] = $term->getName();
    }
  }
}
1
  • I used a different solution, but this is the correct answer to have the issue sorted in a cleaner way. It is a bit sad that D8 requires a custom module to achieve something that with the entities should be easy. To whom is seeking the solution right away: you have to create the same view from the question's screenshot, but starting from content, and use the above code to print the taxonomy name.
    – Elgandoz
    Commented Feb 7, 2018 at 1:17
0

I ended up using an alternative solution, with Taxonomy View Integrator: It overrides the display of the regular view selecting any view you want. It's slighlty easier because there is no need to deal with path of the view page, which is useful if you have different displays/behaviours for different vocabularly.

Taxonomy Views Integrator settings per Vocabulary

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.