I try to achieve the up-side-down scenario of that what many Drupal users know as one of the standart Views views, where a list of nodes has a field (column) listing all terms used with commas like this:

node1 | some_other_field | term1,term2,term3
node2 | some_other_field | term1,term2,term3
node3 | some_other_field | term1,term2,term3

But in the case of this question it is exactly the other way around: A list of terms with a column showing the nodes using the term. And the challenge is that we need the edit link to the term on each row so we cannot use the aggregation trick using the listed nodes view, summarized and grouped by each term. We need to achieve it by using the real terms view, with a final result like this:

term1 | some_extra_term_field | used by: node1,node2,node3
term2 | some_extra_term_field | used by: node1,node2,node3
term3 | some_extra_term_field | used by: node1,node2,node3

Adding the respective relation of node types to the term list view and adding one the node fields (title) using the relation we get a list of many duplicated rows of the same term, each row showing one node under the colum "nodes used".

So how can I force the view to show me the node titles listed on each term row like we can list terms on node list views? Since in Drupal 8 all are entities and terms are just other entities "related" to nodes, it should actualy work both ways out of the box. But it sadly doesn't.

EDIT: Thanks to Clive, who gave me already an idea how to achieve that. But I would prefer a solution in Views UI only for this answer. But if this is not possible, we can go for a custom code/module answer on this then.

  • 1
    I'd imagine you'll need to find/write a custom field handler for this. The one that lists taxonomy terms for nodes (Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid) has been created for that very specific purpose. There's no aggregation involved, it does a separate query for the terms in pre-render. Your own field handler could do something very similar I guess, most of the code is probably written for you in TaxonomyIndexTid
    – Clive
    Jun 4, 2018 at 13:09
  • Thanks for your comment, Clive! But isn't VIews exactly for this purpose: to not write code for a query but to use Views to "set up" a view for that? Do I need to specify my question or do you mean that I can't achieve this in Views without custom code?
    – jbitdrop
    Jun 4, 2018 at 14:54
  • 1
    Absolutely, yes - but conceptually you're not writing a query here. You're running a query, then running another query based on the results of the first one, in order to get related entities. Views, and the query building UI, is responsible for the first query, not the second. The only way to achieve what you want with a single raw SQL query is to resort to terrible things like GROUP_CONCAT (made much worse if you need to include things like URLs in the CSV list). So special code has to be written for these edge cases, and I guess they have to stop somewhere with out-of-the-box features
    – Clive
    Jun 4, 2018 at 15:02
  • 1
    If you're new(-ish) to Views, and you're anything like I was, this won't be the last time you ask yourself well what's the frigging point of it then?...Been there, done that, got the t-shirt :) I can only recommend sticking with it, once you know how it works it's a massive time-saver
    – Clive
    Jun 4, 2018 at 15:04
  • I don't know if this is problematic in terms of performance, manually adjusting the query is probably better if you know how, but Views Field View module is often used in cases like these.
    – prkos
    Jun 4, 2018 at 21:56


Your Answer

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

Browse other questions tagged or ask your own question.