Score:0

Get count of referenced paragraph entities matching criteria

ph flag

I'm trying to get a view of nodes that have an entity reference to a paragraph. The paragraph entity contains a status field. I want the view to show a count of paragraphs that have a status of "done".

I can get a count of all the referenced paragraphs easily enough, but I can't constraint it to paragraphs of a certain status. Is there any way to do this in views?

Edit: Here's what I have so far:

A field defined as a count of the paragraphs:

enter image description here

This shows the count correctly for the full count of paragraphs, but now I want to filter by a field on the paragraph, so I added a relationship to the paragraph:

enter image description here

And a filter on the field in that relationship:

enter image description here

But this only shows nodes that have at least one completed paragraph, the nodes that have zero completed paragraphs stop showing up.

I figure it's some kind of outer join issue which I'm pretty sure I could figure out in straight sql but I don't know how to make views do it.

in flag
Could you share a little more about your approach and what has worked and what hasn't? Sharing some or all of your view configuration might help. Also, have you considered defining the Status field as a taxonomy reference pointing to a taxonomy of Status levels?
Lambic avatar
ph flag
Added some notes about what I've done so far. It doesn't matter if the status field is a taxonomy reference or straight text, it's the fact that it's on a paragraph entity that I believe is the issue.
in flag
Thanks for the additional detail. I suppose a taxonomy would not help here, after all. It sounds like you might need to implement a views hook in order to define a custom field plugin. I'd look at `hook_views_data()` and this turorial: https://www.lullabot.com/articles/building-views-query-plugins-for-drupal-8-part-2. You'll need to register your field for your target entity in the hook, then extend `Drupal\views\Plugin\views\field\FieldPluginBase` for your field plugin. You will probably only need to override the `query()` method.
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.