Hi,

I've noticed a slight bug when trying to implement hook_username_alter() to alter the output of usernames and the webform module. It seems that webform skips formatting the username when outputting it. This can be found on pages such as:

  • node/%node/webform-results
  • node/%node/webform-results/table
  • Submission downloads

Comments

funex’s picture

Status: Active » Needs review
StatusFileSize
new861 bytes

My solution is to to pass the username for each submission through format_username() in webform_get_submissions().
The only drawback is this function requires a loading the user object for each iteration of through submissions - I wonder how expensive this is.
Please see patch attached.

Thanks,

Andy

funex’s picture

StatusFileSize
new861 bytes

I'm not doing very well at this - I uploaded it relative to the wrong path! oops.

funex’s picture

StatusFileSize
new788 bytes

OK lets try this one! :-)

quicksketch’s picture

Status: Needs review » Needs work

Thanks for the patch @andyhails. I think it would be great to consistently format the user name, but this patch puts the formatting in the wrong location (on load instead of on view) and like you say, probably adds a lot of overhead. I'd prefer to see us using format_username() right before the information is displayed, rather than on load. There are many situations (CSV downloads, e-mails) where the user name may not be used at all, or it's not appropriate to run it through format_username (which will make an HTML link in many situations). We should format the username only where it's needed, rather than modifying the loading of submissions.

Additionally, I'd prefer to avoid loading the user account. I think format_username() actually is used in places where a full user object isn't available already (like in comments). If it's possible to just pass in the submission object into format_username(), that might be preferable for performance, though slightly inconvenient for users who are overriding theme_username(). I think we should cater to the majority of users who aren't going to be making that customization and go for the higher-performance/less-convenient approach.

quicksketch’s picture

Title: hook_username_alter() on webform breaks with fields » Usernames not run through format_username()
danchadwick’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Version 7.x-3.x will get critical bug fixes only. Views will be used in the future from the tables above, and the CSV output should probably not be formatted.

danchadwick’s picture

Version 7.x-4.2 will use views for the RESULTS/SUBMISSIONS and RESULTS/TABLE tabs. If you have access to a user name that gets formatted with format_username(), then this might help.