I have a node that people can flag to indicate their attendance/interest in that node's activity. However, I would like to show a list of users who have flagged a given node on that node's page. While I can find a way to show a user's current flag state or a flag count for that node in a view, I can't find a way to do this for the node representation itself.
You can relatively easy do that by adding a views contextual filter for the node id (nid
) with the following configuration:
When the filter value is NOT in the URL:
Provide default value -> Content ID From URL
When the filter value is IN the URL or a default is provided:
Specify validation criteria ->
Your CTs listFilter value format:
Node ID
The flag relationship used should be:
by any user
Of course you can use that view as a block and place it wherever you like.
-
How do I get that view/block to show up at a certain entity view? I can't manage to find that. Or will I have to make a desperate template for that node type? – Erik S Dec 21 '15 at 2:34
-
-
From an overview of all these node types, if you click on one, it takes you to a view of that particular node. On that page, I would want to show this list of users. Should I change what the overview page links to, and create a view for a single node? Or can I add this view (with the list of flagged users) to a node's display page? – Erik S Dec 21 '15 at 10:28
-
1Yes, you can add this View/block to a node's display page. By creating the View's block, that block will be available at the block's list of Drupal (admin/structure/block) from there you can place it to any region (you may very well be [create your own region] (drupal.stackexchange.com/questions/129/…) any where in the node's display page) .Lastly from the block's settings you may set any path(s) that this block could appear as well as permissions settings. – mchar Dec 21 '15 at 11:19
-
Ah, great, that's something I hadn't figured out yet. Now I just need to figure out how to get the view working, so far no users are showing up... Will come back later once I have time. – Erik S Dec 24 '15 at 12:09
As said by mchar, it can be done easily using views.
1) Create a view by selecting your content type.
2) Under Relationships in Advanced tab, select Flags (flag name) by any user and (flag)Flags:user
3) In fields tab, Add user name field and Flag user as relationship.
Hope it will work for you.
-
Ok, then maybe my actual confusion is different. From an overview of all these node types, if you click on one, it takes you to a view of that particular node. On that page, I would want to show this list of users. Should I change what the overview page links to, and create a view for a single node? Or can I add this view (with the list of flagged users) to a node's display page? – Erik S Dec 21 '15 at 10:28