In Drupal 5 and 6, the "Node Reference" and "User Reference" fields allowed site builders to connect different content types to each other and connect nodes to arbitrary users. They were great for building out complex data structures, and in Drupal 7 the two modules live on as a separate project. However, Drupal 7 also heralds the arrival of the entity system, a unifying API for all sorts of Drupal objects like Users, Nodes, Comments, Files, Products, Blocks, and so on. What about creating fields that link to all of those entities? That's where the new Entity Reference module comes in.

Screenshot of selecting an Entity Reference field

Like the Node and User reference fields we're familiar with, Entity Reference fields can be placed on any "fieldable" item in Drupal 7. You must configure what kind of entity you want the field to point to -- unfortunately, it doesn't support fields that can point to many entity types simultaneously. However, it makes up for it by supplying a "multiple-item autocomplete" input widget that can be used across any entity reference field. Like the Taxonomy tags field widget that comes with Drupal core, it allows you to use auto-complete text entry to choose items, and use commas to separate multiple items.

Screenshot of the Entity Reference widget

Entity Reference has only recently entered beta, but it's well-maintained, includes a number of automated tests, features clean integration with the Views module, works smoothly with the Migrate module for data imports, and supports the Devel Generate module's ability to create dummy text. If you need to create fields that reference some of the new and interesting entity types that exist in Drupal 7, or you want to use a slick multi-value autocomplete widget to populate a node or user reference field, check it out!

Published in

If you enjoyed this Article, you may also enjoy...

Jeff Eaton

Thumbnail
Jeff Eaton is world renowned for his opinions on Content Strategy, Drupal development, bacon, gummy candy, and cats.