0

I have a view that lists all users that have flagged a piece of content (using the Flag module). Also, for that content, I have certain user references attached (using the References module).

So:

  • User can flag a piece of content.
  • Content can reference user.

I want to be able to have the view show all users that have flagged the piece of content (I have that working correctly), but also show them in the order of:

  1. Users that are referenced by the piece of content.
  2. Username, alphabetically.

I think I just have a mental block from getting this done. Any pointers or advice to help me get this kind of sort working? Note: I also need to have everything done in one display, since it needs to be sortable and filterable.

2

I have an idea! Use your current block to limit the list to users who are referenced in the node, and then add an ATTACHMENT to the block listing users who have flagged it who weren't referenced in the node.

That way you can separate them our and sort independently, but they'll still appear as if they're displayed in the same view.

Here are the exact steps:

  • Add an additional relationship that is the node user reference field, but reversed:

enter image description here

  • I added the 'Content: nid' field with the above relationship to my view just while testing, and that was helpful, so I'm including it as a step...

  • Add that field 'Content: nid' using the user-reference relationship to your set of contextual filters too, if you're using it, to make sure the content they're referenced in is the current node (don't want to sort them first just because they're referenced in SOME node on the site, right? ;-))

enter image description here

  • Add an attachment to your view, and set it to display directly after your existing page or block. In this one, you'd want to do the exact same as above, however, when you're setting the contextual filter, select to 'Exclude' the matching answers (you'll find that check box in the collapsed 'More' section at the bottom.

enter image description here

  • This is a good solution for simply displaying all the users on a page—however, I still need to be able to sort and filter (using exposed filters) all the users together, so this won't work for this site. – geerlingguy Apr 16 '13 at 14:50
  • Oh, your question only mentions the display... – Boriana Ditcheva Apr 16 '13 at 14:58
  • I'll update it, then :) – geerlingguy Apr 16 '13 at 16:54
  • Given your new requirement, I suspect you'll have to actually modify the SQL in your view to accomplish something like that. If no one else chimes in to say differently, the samples in this question may help you (using hook_views_query_alter()): drupal.stackexchange.com/questions/73/custom-query-in-views. – Boriana Ditcheva Apr 16 '13 at 17:44
  • I was hoping there was a way to do it without the query_alter hook—I've been banging my head against the wall with that, too (it's hard to conceptualize the joins and compound order-by clause I'll need). But I'll give it another go. – geerlingguy Apr 16 '13 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.