2

Drupal 7. I have a content type that can be flagged with 3 different flags. I need to display a view of users who have not flagged any of them.

The users that are allowed to flag are listed in an entity reference field on the node. My view is a content view that has the relationship to the entity reference list to get the users, then I have a relationship to Flags: User's flaggings for each of the different flags. There is also a Contextual Filter for the current node.

When I add a filter for Flags: Flagged (False) related by the User's Flagging, it seems to check if the user has flagged any content with that flag, not just the current node.

Looking at the flagging table, it seems like I need to do some kind of combined column check. I need to know if the uid has any entries in the table with the same entity_id (node id in this case).

Will I have to alter the query in code? Any hints on that would be great too. Otherwise, if it can be done in the UI, that would be nice.

1 Answer 1

2

It's always tricky when trying to display "things that aren't" because Views rely on things that are, even when querying out empty fields.

I haven't tried to recreate your example, but here are some comments that might help start you up:

Do it for one flag first

Once you have a working example related to only one flag it's easy to repeat the steps adding conditions for other flags. This is difficult enough to figure out for one flag alone.

List NOT flagged

To display content that isn't flagged, you must untick the option Include only flagged content in the Flags: flagname Relationship, and then use the Filter Flags: Flagged set to Not flagged:

How to list content that is not flagged.

Users who aren't here please identify yourselves!

It's impossible to list users who "aren't". You can only list all of them and then filter out the ones who "are".

If you start with Content Views, you can list content that hasn't been flagged, and you can show which users flagged it, but you can't list which users haven't flagged it, because there is no relationship between nodes and users who haven't flagged it!

A better option might be to go with User View. You can add Relationhip to the relevant flag, don't limit only to users who flagged, and adjust to Any user. Add Contextual filter Flags: Entity ID and set the default value to Content ID from URL, but don't forget to Exlude under More. Add a Filter Flags:Flagged and set to Not Flagged, but this way you only get users that haven't done any flags on any nodes.

You need some additional module to combine and help with showing things that aren't. With Content Views you can't list usernames of people who haven't flagged, while with User views you can only show people who haven't used the flag at all, you can't show a user who hasn't flagged a node if that user flagged another node with that same flag.

Views Reference Filter module

This module has a cryptic explanation on its project page, but could be useful in your case to pass one views results to the main views display to combine the results so you get something meaningful.

Views Reference filter module can be used to filter a View with the results of another (Entity Reference) Views Display. It can pass arguments to the embedded view:

Arguments for Views Reference Filter

You can probably create one View listing all Users who are allowed to flag Content, create another view that shows the users that have flagged it, then filter the first view with the negative second one. Just remember that the Field type of the Views Reference Filter must match the type of ER Views Display type (uid-user).

Introduce Flags Relationship

You need to add a Relationship that contains information about the node flag status. I doubt you can do that with User's flaggings without another Relationship before it that connects to the user who flagged, which is a roundabout way.

Just use the Flags: flagname, don't limit to Include only flagged content, and do set it to Any user.

Later you can add more Relationships to display users names etc, first you need to focus on making the filtering work.

2
  • It would be great to know more about Views Reference Filter. Does it allow arguments to be passed from the parent view to the embedded filter? That's what I think I would need to do in my case. You are right about the cryptic explanation. Thanks for the answer though, I think it has set me on the right path!
    – TommyK
    Commented Aug 12, 2018 at 1:26
  • Yes, Views Reference Filter does allow arguments, but they are passed from the Embedded View Display to the Parent one. I'll add a screenshot to my answer. That module basically provides a way to filter one View with the results of another View. Another possibility might be to use Views Field View that enables to embed one View into Rows of another View, with arguments if necessary.
    – prkos
    Commented Aug 12, 2018 at 16:01

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.