February 27, 2016
Using Profile2 With Panels - Building the Right Relationship

Profile2 is a useful Drupal module for creating “Profile” objects – essentially, fieldable entities that attach to and function as an extension of the User object. This is very useful when you have fields that you want to associate with your users – but only some users. Instead of sticking the fields on the User object (which would make them available to everyone), putting them on a Profile allows the to only be visible to those who need them, and overall presents a much cleaner solution.

A diagram of the User and Profile objects

A common use case for those using Profile2 is probably to display these fields on the User page (/user/<uid>). If you’re using Page Manager / Panels, which you should be, then you’ll need to create a relationship between the User object and the Profile object in order to get at the fields. This relationship (set it up from the Contexts menu in your Panels variant) is called “Profile from User”.

Unfortunately, at time of writing, this relationship does not work in the released version of Profile2 (which is 7.x-1.3). The relationship is certainly present – you can select it – but it doesn’t work. Depending on your setup, the Profile fields are either not accessible at all, or will produce the wrong data.

This relationship does not work!

Fortunately, the issue is fixed in the latest Dev release (at time of writing, this was 7.x-1.x-dev). This latest Dev release has a new relationship, “Profile2 from user”, which produces the right data.

This is the one we want.

Be aware: if you have already built a (nonfunctional) Panel with the 7.x-1.3 module version, your relationship will not automatically upgrade. You’ll have to remove the broken one and insert the new one.

Fortunately for me, I didn’t have to update all my references to that relationship in my Panel content, but I suggest checking to ensure they still work after swapping the relationship.

The last time Profile2 got a release was 2012…the last Dev release was 2015. It’s time for a new release, guys!