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
Comment #2
suraj_vantagode commentedComment #3
suraj_vantagode commentedComment #4
suraj_vantagode commentedI 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.
Comment #5
malte.koelle commentedI have created a patch for this problem, with the solution of @Suraj_Vantagode.
Comment #6
suraj_vantagode commentedThanks @malte.koelle. It will work with this patch.
Comment #7
suraj_vantagode commentedComment #8
avpadernoA bug isn't fixed until the patch is committed on the project repository.
Comment #9
avpadernoI am updating the title to reflect what the actual issue is.
Comment #10
avpadernoComment #11
avpadernoComment #12
hanoiiI think my patch on #3087885: Add an entity operation instead of a user list fixes this with a different/more flexible approach.
Comment #13
avpaderno@hanoii Yes, adding an entity operation instead of having a page just to switch user seems a better solution for me too.
Comment #14
avpadernoLet's focus on implementing #3087885: Add an entity operation instead of a user list.