1 user.entity.inc UserStorageController::attachLoad(&$queried_users, $revision_id = FALSE)

Overrides EntityDatabaseStorageController::attachLoad().

Parameters

User[] $queried_users: The user entities for which fields should be attached.

Overrides DefaultEntityController::attachLoad

File

core/modules/user/user.entity.inc, line 290
Entity classes and controllers for User module.

Class

UserStorageController
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) {
    if ($record->picture) {
      $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[] = BACKDROP_AUTHENTICATED_ROLE;
    }
    else {
      $queried_users[$record->uid]->roles[] = BACKDROP_ANONYMOUS_ROLE;
    }
  }

  // Add any additional roles from the database.
  $result = db_query('SELECT role, uid FROM {users_roles} WHERE uid IN (:uids)', array(':uids' => array_keys($queried_users)));
  foreach ($result as $record) {
    $queried_users[$record->uid]->roles[] = $record->role;
  }

  // Add the full file objects for user pictures if enabled.
  if (!empty($picture_fids) && config_get('system.core', 'user_pictures')) {
    $pictures = file_load_multiple($picture_fids);
    foreach ($queried_users as $entity) {
      if (!empty($entity->picture) && isset($pictures[$entity->picture])) {
        $entity->picture = $pictures[$entity->picture];
      }
    }
  }
  // Call the default attachLoad() method. This will add fields and call
  // hook_user_load().
  parent::attachLoad($queried_users, $revision_id);
}