Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function UserController::attachLoad

Attaches data to entities upon loading.

This will attach fields, if the entity is fieldable. It calls hook_entity_load() for modules which need to add data to all entities. It also calls hook_TYPE_load() on the loaded entities. For example hook_node_load() or hook_user_load(). If your hook_TYPE_load() expects special parameters apart from the queried entities, you can set $this->hookLoadArguments prior to calling the method. See NodeController::attachLoad() for an example.

Parameters

$queried_entities: Associative array of query results, keyed on the entity ID.

$revision_id: ID of the revision that was loaded, or FALSE if the most current revision was loaded.

Overrides DrupalDefaultEntityController::attachLoad

File

modules/user/user.module, line 302

Class

UserController
Controller class for users.

Code

function attachLoad(&$queried_users, $revision_id = FALSE) {
 // Build an array of user picture IDs so that these can be fetched later.
 $picture_fids = array();
 foreach ($queried_users as $key => $record) {
 $picture_fids[] = $record->picture;
 $queried_users[$key]->data  = unserialize ((string) $record->data );
 $queried_users[$key]->roles = array();
 if ($record->uid) {
 $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID ] = 'authenticated user';
 }
 else {
 $queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID ] = 'anonymous user';
 }
 }
 // Add any additional roles from the database.
 $result = db_query ('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(
 ':uids' => array_keys ($queried_users),
 ));
 foreach ($result as $record) {
 $queried_users[$record->uid]->roles[$record->rid ] = $record->name ;
 }
 // Add the full file objects for user pictures if enabled.
 if (!empty($picture_fids) && variable_get ('user_pictures', 0)) {
 $pictures = file_load_multiple (array_filter ($picture_fids));
 foreach ($queried_users as $account) {
 if (!empty($account->picture) && isset($pictures[$account->picture])) {
 $account->picture = $pictures[$account->picture];
 }
 else {
 $account->picture = NULL;
 }
 }
 }
 // Call the default attachLoad() method. This will add fields and call
 // hook_user_load().
 parent ::attachLoad ($queried_users, $revision_id);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.