Drupal Learning Journal 16. Interests field in profiles
I was asked to make the “interests” field of the user profiles in a Drupal 7 sites pivoting, i.e. a way to enable users to find other users with the same interests. Sounds simple doesn’t it? It wasn’t so.
1. First of all the existing “interests” field contained long sentences that the users filled in. Not exactly easy to “pivot.” OK, we made the decision with the client to have add a new field to the profiles, which would have the list of keywords (interests) that are possible to pivot around.
2. Next decision how to add the new field for these terms? There are two options both had its cons and pros, neither of them are perfect.
A, Add a new field to the account, under “Configuration » Account Settings »Manage fields.” The advantage of this solution is that it allows the new field to be of a “Term reference” type. That means that I can assign a specific Taxonomy to it, e.g. an “Interests” vocabulary to it. This solution would allow free tagging and auto fill, so users could easily add new terms to the list. This also means that each term on the user profile and on the user list page can easily made clickable. Ideal, right? Nope. The problems with this solution are:
- The location of the new field on the registration page is not standard. On the registration page it would be way under or way above compared to the rest of the fields and even compared to the “Create new account” button. It proably can be moved to the right place, but only by changing the appropriate tpl.php file, not by using the web based UI
- Same applies to the user profile page. The field created this way would be way below the save button and not under the same tab (in our case “Personal Information”) as the rest of the fields.
- I don’t exactly recall(, because I went with the other solution), but I think its display was also problematic on the userlist page.
B, Add a new field to the Profile at “Configuration » People » Profiles“. The advantages are clear:
- Earlier this week I was told by a Drupal guru that the proper way to add fields to the user’s profile is here. He told me this in the context of use trying to make profile fields truly required, i.e. no way for a user to access the site without filling them out. Putting these fields into the other area didn’t make them fully required.
- The field(s) in the Profile puts them to the standard location and integration with the rest of the profile.There is one major problem with this solution: it doesn’t allow connecting a taxonomy to the new field. My (relevant) options for what kind of filed it can be are checkbox, list selection, free form list. Using the checkbox option would require me to create a checkbox for every single possible interest: not viable. The list option would allow users to select only one interest: not enough. This left me with the Freeform list. That is fine as long as we regularly synchronize the list and making sure that close variants of the same thing are combined.
3. The next issue is are how to display and link the contents of this new “interests” field on the userlist page. When I started working on this issue the site had a mostly standard Userlist page. It had a few issues on its own:
- Custom theming was difficult to override/change when developing the list
- The list was sorted by chronological order of access, putting the user who last signed on to top
- It was displaying the username. We asked our users to use their full name as username,s but not everybody did, so the list was not as informative as we hoped for.
So I decided the build a new user directory using the “Views” module. The results were mixed.
- I still have issues with theming in this new directort, but only when I try to display the users’ profile images.
- The list is sorted alphabetically by name, which makes more sense. I also have more granular access to sorting and paging. E.g. when the bugs in the Views module will be sorted out it will be possible for users to change the default sorting, e.g. sort by countries. Right now there aren’t a lot of users so I left the number of users displayed on a screen unlimited. But when we’ll have much more users I can set that number to anything we want to, e.g. 50 or 100. (and users will be able to page through the userlist by looking at 50/100 at a time and using pagination links to move on.)
- I can set whatever field I want to be shown on the userlist. (This applies to both kind of userlists, but the lack of theming works better on the new one.)
- There is a “Members” link in the breadcrumb to go back to the full list when looking at the sublists (e.g. members from a certain country.)
4. The last issue, closely related to the previous one, is how to display and link the content of this new “interests” field on the individual profile pages. Right now, in both directories clicking on the a country or an interest takes you to a page which lists the appropriate users in the old style, standard directory. This is obviously not ideal for the new Views based directory, but I ran out of time on trying to figure out how to create a userlist page just for a people from a certain country or people interested in certain topics. I strongly believe that the Views based directory is better, but without fixing this last detail (and the theming) we may not be able to make it work.
As I ran out of steam and ideas I called in my colleague to help and curious how he will solve the above.