public function getAllGroupsForUser($uid) {
    $groups = &drupal_static(__FUNCTION__);

    // Get the memberships for the user if they aren't known yet.
    if (!isset($groups[$uid])) {
      $group_content_types = GroupContentType::loadByEntityTypeId('user');
      $group_content_types = array_keys($group_content_types);

      $query = $this->database->select('group_content_field_data', 'gcfd');
      $query->addField('gcfd', 'gid');
      $query->condition('gcfd.entity_id', $uid);
      $query->condition('gcfd.type', $group_content_types, 'IN');
      $query->execute()->fetchAll();

      $group_ids = $query->execute()->fetchAllAssoc('gid');
      $groups[$uid] = array_keys($group_ids);
    }

    return $groups[$uid];
  }