public function MasqueradeCallbacks::renderCacheLink in Masquerade 8.2
#post_render_cache callback; replaces placeholder with masquerade link.
Parameters
int $account_id: The account ID.
Return value
array A renderable array containing the masquerade link if allowed.
File
- src/
MasqueradeCallbacks.php, line 57
Class
- MasqueradeCallbacks
- Masquerade callbacks.
Namespace
Drupal\masqueradeCode
public function renderCacheLink($account_id) {
/** @var \Drupal\user\UserInterface $account */
$account = $this->entityTypeManager
->getStorage('user')
->load($account_id);
if (masquerade_target_user_access($account)) {
// @todo Attaching a CSS class to this would be nice.
return [
'masquerade' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Masquerade as @name', [
'@name' => $account
->getDisplayName(),
]),
'#url' => $account
->toUrl('masquerade'),
],
];
}
return [
'#markup' => '',
];
}