function realname_load_multiple in Real Name 2.x
Same name and namespace in other branches
- 8 realname.module \realname_load_multiple()
- 7 realname.module \realname_load_multiple()
Loads multiple real names.
Parameters
array $accounts: An array of user account objects keyed by user ID.
Return value
array An array of real names keyed by user ID.
Related topics
2 calls to realname_load_multiple()
- realname_load in ./
realname.module - Loads a real name.
- realname_user_load in ./
realname.module - Implements hook_ENTITY_TYPE_load().
3 string references to 'realname_load_multiple'
- realname_delete_all in ./
realname.module - Delete all real names.
- realname_delete_multiple in ./
realname.module - Delete multiple real names.
- realname_user_update in ./
realname.module - Implements hook_ENTITY_TYPE_update().
File
- ./
realname.module, line 175 - Provides token-based name displays for users.
Code
function realname_load_multiple(array $accounts) {
$realnames =& drupal_static(__FUNCTION__, []);
if ($new_accounts = array_diff_key($accounts, $realnames)) {
// Attempt to fetch realnames from the database first.
$realnames += \Drupal::database()
->query("SELECT uid, realname FROM {realname} WHERE uid IN (:uids[])", [
':uids[]' => array_keys($new_accounts),
])
->fetchAllKeyed();
// For each account that was not present in the database, generate its
// real name.
foreach ($new_accounts as $uid => $account) {
if (!isset($realnames[$uid])) {
$realnames[$uid] = realname_update($account);
}
}
}
return array_intersect_key($realnames, $accounts);
}