Download & Extend

Dynamic title pattern and additional fields

Project:Alter profile page
Version:6.x-2.6
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I'm working on a site where I wanted to incorporate a "headline" CCK text field into the title of the user's profile. I searched around for something to accomplish this, and found the Alter Profile Page module which did a nice job of making some simple aesthetic changes to the profile page, and figured it wouldn't be that hard after all to modify it, since it already was providing a change to the profile title. So, the attached patch does just what I've described.

The patch is token-module aware, and does two things:

  1. Via a hook_form_FORM_ID_alter call it adds a new field set (see attached image) to the User Settings admin form for specifying a title pattern. If the token module is installed, the description is modified to indicate all tokens can be used, and provides the list in a collapsible and collapsed field set.
  2. Then I modified the hook_profile_alter function at the end to evaluate the pattern. It's passed through a call to filter_xss before the title gets set, to avoid any cross-site-scripting problems that a dodgy user may have introduced in their input.

This in fact winds up being pretty powerful from a titling perspective, as now things in the title can be wrapped in class specifications via any of the standard / default tags (such as what I did in the example with <em class="..."> ... </em>), and then you can style the class so that part of the page title can appear different from the rest, etc.

Would be great if this made it into the module on the next go-round. I've attached a patch against the 2.6 version.

Shawn

AttachmentSize
What the new section looks like49.12 KB
alterprofilepage.module.patch2.95 KB

Comments

#1

Title:Dynamic title pattern» Dynamic title pattern and additional fields

Well, I couldn't leave well enough alone! :-) I also wanted to put more "stuff" up in the summary section, and so modified this module additionally to do so. In particular, I needed to display the user's role there, and possibly some other CCK fields. Token makes these things available, of course, so all I needed to do was kind of repeat the basics for what I'd done with the title, and provide an input area for the extra bits.

So, the attached patch (which includes the changes of the one above, to be applied against 6.x-2.6) makes the title changes as well as provides a text-area for input of additional fields, each on a separate line, with the format title|classes|value. I discovered in my research that specifying an #attributes element in the $account->content['summary']['field_name'] array gets added to the <dt> and <dd> tags, which then of course opens these up to styling via CSS. Hence the middle component for classes. Fields get rendered in the order they're entered.

The new input field shows up and the rendering happens if the Token module is installed. Otherwise the default behaviour continues. Token replacement happens in all of the title, classes, and value fields, making this even more powerful for displaying additional information and styling it depending on certain values. I've used calls to filter_xss() to reduce likelihood of harm based on any CCK tokens coming from user-supplied stuff.

Shawn

AttachmentSize
alterprofilepage.module.cbd-2010-08-27.patch 5.33 KB
nobody click here