Drupal 6, Content Profile default username

I have a content profile set up on a number sites and I noticed when I used User / Node Import recently that I couldn’t assign an import value to the title field of the node profile, which I was using as First Name.
After I did the import. I found out why. The “title” field was defaulted with the Drupal user name.
Which is a very good idea.

So I updated my other content profiles to use this same convention but then I realized that there’s no easy way to default that field value to username.
So I considered a

  • Custom module that overrides the content type Profile and defaults the title with the username. – This is the best option
  • jQuery script in a block that runs on the profile edit pages – This is quick but may miss some pages and relies on javascript and possibly my profile set up (show in tabs)
  • jQuery script in a Views block – This may be slightly better than the static script as it pulls the user name from the database, but it’s is more effort

I settled on the simple jQuery script to make it quick.
I pull the user name from the title of the edit page, which in my configuration is the user name.
I don’t know if this is always the case but it was in this case so it made it easy to use jQuery.

I could potentially use this script in a custom module. But staying server-side and preprocessing the fields would make more sense.
I could also set the script to run anytime the edit page is opened.
The jQuery / Block method relies on known, url configurations that == the profile edit page.
For example: Right now the block is set to
Show on only the listed pages.
With these urls:

user/*/edit/profile
user/*/profile/profile*

I couldn’t remember if this would work with out ‘clean URLs’ enabled but a quick test with

$_SERVER['QUERY_STRING']

showed that the query string is still ?q=user/*/edit/profile. So these listed urls should continue to work.
If I ever include the user profile in a page wizard workflow this block probably wouldn’t show up so that’s another point for the custom module method.
(more…)