Is it possible to create the functionality where, on creating a node, the user can tag friends to associate their friend with the node. Such as in Facebook's tag a friend in a post.

This would require a friends lookup field, which would imply that the users have already approved each other as friends (maybe using User Relationships).

So, the key thing is to provide a lookup field which searches the user's friend list, and also exposes itself to Views.

Ideally, the field would allow you to enter an email address if their friend isn't already on the site (probably asking too much, and could possibly make do with using the Invite module here).

  • It might require some hacking but I'd check out the Entity Reference module: drupal.org/project/entityreference
    – Mike
    Commented May 24, 2012 at 22:16

2 Answers 2


It is definitely possible, and some of the functionality you need already exists.

I would go the route of creating a new field widget for a standard user reference field that tackles limiting the possible list to current friends.

Have a look at user_relationship_views hook_menu implementation for an example of how you would do the user lookup (in this case we're looking up relationship types but you can get the idea). I think the code for doing this with standard user fields in views is pretty straightforward as well if my memory serves me correctly. To find all the relationships with the current user look at the api docs for user_relationships_load().

User relationships already comes with invite module integration (invite user x with y relationship attached to the invitation). The ui isn't that stellar but I'm guessing you could squeeze it into a node form with a little work.


I've implemented it using an entityreference field.


  1. Install and enable the entityreference + Entityreference Views Filter modules.

  2. Create the selection view.

Selection view

The display type should be "Entity Reference."

Selecting the view's display type

The view should be field-based, with the 'Entity reference list' format. You should add the 'Entity Reference View Widget Checkbox: User' field:

Adding the 'Entity Reference View Widget Checkbox: User' field

Then add a name and picture fields.

  1. Now, that you've created the ER user selection view, it's the time to add an entity reference field to the node's content type. Go to your content type's fields page and add a new entity reference field, with the 'View' widget:

Defining the new field

  1. Field settings: 'Target Type' should be 'User', for the 'Entity Selection' field select 'Views', and for the view select the view from step 3 (friends_selection):

Fixed field settings page

  1. Now you get the standard CCK Field definitions page. Here select the max number of people you allow to tag (probably bigger then 1).

Field definitions

  1. Now create a new node - you will see the new field.

The new node screen with the new field

  1. Click on the 'add items' link inside the view field and you will get the selection popup.

Selection popup

  1. Check the friends you want and click on the buttons on the bottom of the popup:
    • "Add items and close window" will select items on the current view page.
    • "Add selected items" will allow you to select more friends from the next view page.


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.