Grumpy Monkey

Using Views to provide better userreference reverse links

Recently, I built a site for a recruitment agency. Each advertised vacancy has a userreference field (userreference is bundled with the CCK module) to associate the vacancy with the relevant recruitment consultant.

One of the nice features about userreference is that it lists all the nodes that reference a certain user on that user's "user" page (the default page they see when they log in). You can enable this by editing the field (go to Manage Fields for the content type you're using) and selecting "Reverse link". Really simple.

However, I was asked to amend the listing to include another CCK field, a vacancy reference number, to make the listing more useful for the consultants. The listing is generated by usereference's implementation of hook_user and trying to override this seemed a little heavy-handed.

So I didn't bother. I used Views and ended up with something much more useful.

The view itself is really simple: I set up a normal node-based view and added the userreference field as an argument. By passing it the ID of the logged-in user (choose "Provide default argument", then "User ID from logged in user"), the view only displays those nodes whose userreference field matches. Excellent! A couple of minutes configuration later and I had a table-based view with sortable columns and all the information the consultants need to hand.

To add it to the user page, I set up a block display and on the block configuration page I set it to appear on the user page. To finish off, I unchecked the "Reverse link" option. No coding required, and a much more useful page for the consultants. Win!

BlogDrupalviews