The list of users on /admin/people/switch-user-list doesn't list all the users existing on the site.

This happens because the controller, in userSwitchList(), doesn't output the pager.

  public function userSwitchList() {

    $_uid = $this->currentUser->id();
    $query = $this->database->select('users_field_data', 'u');
    $query->fields('u', ['uid', 'name', 'mail']);
    // For the pagination we need to extend the pagerselectextender and
    // limit in the query.
    $query->condition('uid', $_uid, '!=');
    $pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(10);
    $results = $pager->execute()->fetchAll();

    // Initialize an empty array.
    $output = [];
    $header = ['#', 'Name', 'Mail', 'Operations'];
    // Next, loop through the $results array.
    foreach ($results as $result) {
      if ($result->uid != 0) {

        $url = Url::fromUri('internal:/admin/people/user/' . $result->uid);
        $_link = Link::fromTextAndUrl($this->t('Click Here'), $url);
        $output[$result->uid] = [
          'userid' => $result->uid,
          'Username' => $result->name,
          'email' => $result->mail,
          'link' => $_link,
        ];
      }
    }

    $element[] = [
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $output,
    ];

    return $element;
  }

Comments

Suraj_Vantagode created an issue. See original summary.

suraj_vantagode’s picture

Priority: Major » Critical
suraj_vantagode’s picture

Issue summary: View changes
suraj_vantagode’s picture

I got it finally. The issue what i found out is, they're fetching the data from DB with pager but while putting up into table they are not adding pager element. below part is missing from the module.

    $element['pager'] = array(
      '#type' => 'pager'
    );
malte.koelle’s picture

Status: Active » Needs review
StatusFileSize
new441 bytes

I have created a patch for this problem, with the solution of @Suraj_Vantagode.

suraj_vantagode’s picture

Thanks @malte.koelle. It will work with this patch.

suraj_vantagode’s picture

Status: Needs review » Fixed
avpaderno’s picture

Version: 8.x-1.5 » 8.x-1.x-dev
Status: Fixed » Needs review
Issue tags: -Drupal 8.x

A bug isn't fixed until the patch is committed on the project repository.

avpaderno’s picture

Title: User Switch module not showing up all the users in list. » The user list doesn't have a pager

I am updating the title to reflect what the actual issue is.

avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

StatusFileSize
new2.35 KB
hanoii’s picture

I think my patch on #3087885: Add an entity operation instead of a user list fixes this with a different/more flexible approach.

avpaderno’s picture

@hanoii Yes, adding an entity operation instead of having a page just to switch user seems a better solution for me too.

avpaderno’s picture

Status: Needs review » Closed (duplicate)