Score:0

Views: count flaggings per entity-referenced node

pe flag

I have a flag called Collect. (Flag is individual, and enabled on multiple content types.) The flag has an entity reference field to a content type called Bucket. When users flag nodes, they go to a form and select the bucket for the flagging in the entity reference field (field_bucket_select).

Users can view their Bucket list in a view that filters on 'current logged in user' (as well as the content type) so they see only the Buckets they created--so the view has a content author relationship.

The problem: I want this view to include a count of flaggings or flagged nodes, whichever works. There's no 'count' field for that available without a relationship, so I add the relationship for field_bucket_select.

Immediately, Buckets are listed multiple times in the view--exactly the number of times as there are flaggings related to each.

I go into the view advance settings and turn on distinct. No change.

Also, if I add the count field, the counts are odd.

I'm thinking this is not an usual need, so I'm just doing it wrong. Guidance appreciated.

(Drupal 9)

cn flag
What type of entity is the Bucket list view showing? For basic info on how to set up flag count see here: https://www.drupal.org/project/flag/issues/3178501#comment-13881585
pe flag
The Bucket list view lists nodes of the Bucket content type.
pe flag
I checked out the discussion at the link, but as it notes the flag count module doesn't actually provide an example view. It doesn't seem to address the situation where one needs to count flagged nodes or flaggings by way of an entity reference between a parent node (a Bucket) and each flagging.
cn flag
Yes, you are in unknown territory. Flag for Drupal 8/9 is not yet complete and some things, particularly related to Views support, are poorly documented and have not yet been implemented. My guess is you will probably have to code this yourself; I have been using flaggings with fields on my site, and I had to add a fair amount of custom code to get it to work.
pe flag
Thanks. I don't know how to code that, so we'll have to see if the project will be accepted without that for now... or hire a bit of custom dev.
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.