Contributed Modules Unite! Working in Harmony on the Drupal 7 User Account Page
If you have more than a few Drupal contributed modules on your site (especially ones related to enhanced user features), you may soon discover that a bunch of modules want to add content to the user account page. On a recent Drupal 7 site build, for instance, I had modules like Userpoints, User Relationships, and Masquerade all competing for real estate on this page with other elements like the default user "History" section and fields added to the user account.
But what if you want to better control the look, feel, and usability of this page without having to spend a lot of time with custom theming? What if you want to simply control the order of items on this page so that the most important elements are at the top and the page follows a logical and sensible flow given the features of your site?
Fortunately, in Drupal 7, there is a straightforward way to do exactly this.
In Drupal 7, not only does Field UI's "Manage fields" and "Manage display" pages let site builders re-order fields, but it also allows the re-ordering of non-field components. Using hook_field_extra_fields(), you can expose your module's "pseudo field" components on fieldable entities.
The trick, of course, is that you need all modules that interact with the user account page to add their pseudo fields to the user entity. Then, you'd be able to re-order any of these fields and pseudo fields to your heart's content.
As an example, here is the code that was recently added to the Userpoints module to include this functionality:
<br>/**<br>* Implements hook_field_extra_fields().<br>*/<br>function userpoints_field_extra_fields() {<br> $extra['user']['user'] = array(<br> 'display' => array(<br> 'userpoints' => array(<br> 'label' => t('!Points', userpoints_translation()),<br> 'description' => t('!Points related information and actions.', userpoints_translation()),<br> 'weight' => 0,<br> )<br> )<br> );<br> return $extra;<br>}<br>
So what is the result? Check out our new "Manage display" page:
And the user account page looks much better too:
For more information, see the API page on hook_field_extra_fields at this link:
http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
Happy coding! :-)
Tags: