Because I am using the handy ldap_integration module, my usernames are restricted to the usernames in our directory and are in the form last name + first initial. I am in the process of setting up sites for our schools, and I would like to be able to have teachers have more user friendly display names "John Smith" or "J. Smith" or "Mr. Smith" appear on the content they create.

With the help of Drupal community members, I created a profile field and have successfully incorporated it into some displays via node-xxx.tpl.php templates. However, there are still other places where the username value is baked into the code, blog.module being one example. In trying to find all the occurrences of username, I am heading into territory I don't want to be in, namely modifying the code of modules.

My question, then, is this: Is there any way for me to replace all occurrences of username with my "profile_display_name" field in such a way that I don't have to touch any code besides my own templates?

(Any old Frontier/Manila developers out there remember the finalFilter scripts where we could substitute our own values for any of a host of variables just before a page was rendered? This is the kind of thing I'm looking for.)

Thank you.

Comments

jvandyk’s picture

Yes, I remember the page table. Pardon me while I pause to stroke my grey beard.

Theming is the closest we've got to that.

nevets’s picture

If all the code in question uses the function format_name() you could modify format_name (found in includes/common.inc) to do this.

Or this might work, by writing a small module that

  • Implements the user hook and handle the case for when the users information is loaded. I think you could overwrite the user name this way so $user->name is no longer the login name but instead reflects the value of your profile field.
  • You would need to something similar with the nodeapi for the case when a node is loaded
  • And something similar for comments if there is an appropriate hook