function name_user_load in Name Field 7
Same name and namespace in other branches
- 8 name.module \name_user_load()
Implements hook_user_load().
File
- ./
name.module, line 272 - Defines an API for displaying and inputing names.
Code
function name_user_load(array $accounts) {
// In the event there are a lot of user_load() calls, cache the results.
$names =& drupal_static(__FUNCTION__, array());
$field_name = variable_get('name_user_preferred', FALSE);
if ($field_name && ($instance = field_info_instance('user', $field_name, 'user'))) {
$format = name_get_format_by_machine_name($instance['settings']['override_format']);
if (empty($format)) {
$format = name_get_format_by_machine_name('default');
}
foreach ($accounts as $uid => $acccount) {
if (isset($names[$uid])) {
$accounts[$uid]->realname = $names[$uid];
}
else {
if ($items = field_get_items('user', $acccount, $instance['field_name'])) {
// We still have raw user input here.
$items[0] += name_field_parse_additional_components('user', $acccount, $instance);
$accounts[$uid]->realname = name_format($items[0], $format, array(
'object' => $acccount,
'type' => 'user',
));
$names[$uid] = $accounts[$uid]->realname;
}
}
}
}
}