While working on #614444: More consistent RDFa logic for username, we came across the problem that what's passed to theme('username') as the 'account' variable is not an account object in the sense of being the result of a user_load(). Instead, it's just an object that may have 'uid' and 'name' properties as well as possible 'homepage' which real account objects don't have. When called from template_preprocess_node() and template_preprocess_comment(), it's actually set to the node or comment object, because both of these objects have the needed properties. This isn't necessarily a problem, and it's been this way in past versions of Drupal, and maybe it even makes sense, because why call user_load() if you don't need any of the additional data that it would return in order to theme the username? But, rdf_preprocess_username() does need to get the full account object, and therefore, it does call user_load().
- Is this appropriate?
- This means other
*_preprocess_username()functions will also need to call user_load() if they want the full account object. Given that calling user_load() on a uid that it's already been called on is fast, is this a problem? - Is it a WTF that we call something $variables['account'] that's not really an account object?
I don't have a proposal. Instead, I'm posting this to solicit thoughts on whether any of this is something that needs solving.
Comments
Comment #1
sunRelated but different issue: #585838: Consider a generic $entity->user property
Comment #2
effulgentsia commentedAlso, #719376: theme_username: people with "administer users" permission should be able to see "username" as link may require a fully loaded account object in template_preprocess_username().
Comment #3
eclipsegc commentedRelated to this is the issue that if you don't pass an account and instead only pass a name (something the docs seems to suggest is quite possible, as does the code specifically in theme_username()) the name is scrubbed out somewhere between theme() and theme_username() so we get Anonymous as the username, and it's linked the the desired link_path regardless.