function UserStorageController::attachLoad

Overrides Drupal\Core\Entity\DatabaseStorageController::attachLoad().

Overrides DatabaseStorageController::attachLoad

File

drupal/core/modules/user/lib/Drupal/user/UserStorageController.php, line 25
Definition of Drupal\user\UserStorageController.

Class

UserStorageController
Controller class for users.

Namespace

Drupal\user

Code

function attachLoad(&$queried_users, $load_revision = FALSE) {
  foreach ($queried_users as $key => $record) {
    $queried_users[$key]->roles = array();
    if ($record->uid) {
      $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID;
    }
    else {
      $queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = DRUPAL_ANONYMOUS_RID;
    }
  }

  // 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;
  }

  // Call the default attachLoad() method. This will add fields and call
  // hook_user_load().
  parent::attachLoad($queried_users, $load_revision);
}