protected function SwitchUserBlock::buildUserList in Devel 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::buildUserList()
- 8 src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::buildUserList()
- 8.2 src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::buildUserList()
Builds the user listing as renderable array.
Parameters
\Drupal\core\Session\AccountInterface[] $accounts: The accounts to be rendered in the list.
Return value
array A renderable array.
1 call to SwitchUserBlock::buildUserList()
- SwitchUserBlock::build in src/
Plugin/ Block/ SwitchUserBlock.php - Builds and returns the renderable array for this block plugin.
File
- src/
Plugin/ Block/ SwitchUserBlock.php, line 239
Class
- SwitchUserBlock
- Provides a block for switching users.
Namespace
Drupal\devel\Plugin\BlockCode
protected function buildUserList(array $accounts) {
$links = [];
foreach ($accounts as $account) {
$links[$account
->id()] = [
'title' => $account
->getDisplayName(),
'url' => Url::fromRoute('devel.switch', [
'name' => $account
->getAccountName(),
]),
'query' => $this
->getDestinationArray(),
'attributes' => [
'title' => $account
->hasPermission('switch users') ? $this
->t('This user can switch back.') : $this
->t('Caution: this user will be unable to switch back.'),
],
];
if ($account
->isAnonymous()) {
$links[$account
->id()]['url'] = Url::fromRoute('user.logout');
}
if ($this->currentUser
->id() === $account
->id()) {
$links[$account
->id()]['title'] = new FormattableMarkup('<strong>%user</strong>', [
'%user' => $account
->getDisplayName(),
]);
}
}
return [
'#theme' => 'links',
'#links' => $links,
'#attached' => [
'library' => [
'devel/devel',
],
],
];
}