Over the years, I have noticed a significant increase in the need for businesses to create user dashboards from which their customers are provided account details, up-to-date reports, downloadable documents and other important information. As more clients ask for user-driven websites that provide user-specific information, the need to relate or reference various types of content/data together is becoming commonplace.
I live in Dallas, Texas so let’s use this scenario. Imagine you are an energy company that provides partnership opportunities to individual investors. Each partnership consists of three gas wells. At the end of each month, your investors should be provided with personal financial reports, drilling reports, etc. Investors should also have the ability to view a list of the Partnerships they belong to and the wells that are attached to that Partnership. This information is shared across any user who belongs to the Partnership. Are you with me so far?
While this might be a nightmare to program, the use of Drupal 7 entity references makes this possible within a fraction of the time.
Process for using Drupal 7 Entity References
- Create three content types – Document, Partnership, Well
- Install and configure Entity reference, which provides a field type that can reference arbitrary entities.
- Add user references to both the Document and Partnership content types. This allows you to attach/associate specific users with this content.
- Add a node reference to the Well content type and under Field Settings > global settings, select Partnership, which is the type of content you would like referenced. This allows you to reference/associate a Partnership with a well.
These simple steps provide you with a basic framework from which a user could login to the site, be directed to their dashboard, and gain access to documents that belong to them, Partnerships they are associated with, and potentially a map which provides a listing of all the wells they own interests in. Pretty cool!
Obviously, there are security measures that need to be considered when creating user-specific dashboards of data, but we will leave that for another discussion at another time.
If you’ve solved some fairly complex issues using user or node references, I would love to hear from you. The use cases seem endless. If you are interested in other ways to use the Entity API, check out Randall's post.
Share your comments below!