For an experimental Drupal 7 site, I would like attach a single node to another entity (this might be users, other nodes or even organic groups). The reasoning is fairly simple, say I have several users active and they can gain badges for activity just like in any stackexchange platform. Each badge is represented by a single node. Now, how could a user get the same badge multiple times?

Using entityreference, I can attach the same reference multiple times, but I am struggling with the output, it will show the same badge multiple times instead of only badge name and a counter. Is there already a module for that I haven't found yet? Can you think of a better way to do it?

Badges might not be the best example as you normally wouldn't lose any. Think of a trading card game might be better, as you can have the same card multiple times and trade it with another user. So, in the end I would need a way to add and remove the references. But this will be custom code, I guess.

EDIT (in answer to Webdrips' comment): As said in the very beginning, it's just an experiment so far, we are trying to use Drupal in unconventional ways in order to explore the full capacity of Drupal as a framework.

So, I came up with a better example to illustrate what I would like to achieve: let's say I am building a browser game. Game users will be normal Drupal user entities. An user may have several normal fields like health (number), name (text) and gender (list). Additionally, this user can collect items where each individual item type can be found multiple times.

Several players can be in a clan (organic group). This group has a central storage. So, each individual player of that group can place an item in the central storage.

Technically, I need a relation between user and item (for each item type) which also holds the number of items (e.g. Player1 has 5 nails). If he places 2 nails in the central storage, I need to change the relation between user and item (e.g. Player1 now has 3 nails) as well as the relation between organic group and item (e.g. Group1 has 2 nails).

So I am actually looking for a way to connect an item node (e.g. nails) to other entities (users, organic groups, ...) along with an additional value (item count).

I hope this renders my problem/question in an easier-to-understand way.

I've come across the User Points module and for keeping track of game points in my example this might be the right way to go, but imho it's not suited for the item thing.

  • Have you looked at the User Points module, and the slew of contributed modules that go with it: drupal.org/project/userpoints_contrib? There's a module called Userpoints Badges, but you say that's not exactly what you're looking for. Unfortunately, I don't really understand exactly what you're trying to accomplish, so I recommend re-wording your question with a specific example.
    – Webdrips
    Commented Oct 10, 2014 at 12:55
  • @Webdrips I have added a new section to the question.
    – Paul
    Commented Oct 10, 2014 at 13:09

2 Answers 2


Somehow it kept slipping my attention, I was probably focussed too much on specific ideas, but as it turns out, there is already a module for that, it's simply called Relation.

It's not that straight forward to use (imho), but it essentially creates relations between entities. The created relations are also entities and thus fieldable. By creating a relation type (A [owns] B / B [is owned by] A), I can add a custom field "amount" which holds the information how many Bs are owned by A.

The result (one custom view block added plus a single line of CSS) looks like this. Proof of concept.


Note: The following approach would work but is very custom. Some contributed modules for badges functionality exist and may work for your case, but I have not tried them.

You could still use Entity Reference module and create a custom field formatter for the reference field.

You need to group and count the references that have the same node id, and then pass it to a theme function or template, alongside the fields you want to display of that content type.

For how to create a field formatter for entity reference fields, see both Entity Reference and Examples modules source code. The source code of Entity reference multiple display and Field Extractor contributed modules may help as well.

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.