You are here

function masquerade_toolbar in Masquerade 8.2

Implements hook_toolbar().

@todo Nest this with the "View profile", "Edit profile", and "Log out" links under the username tab.

File

./masquerade.module, line 53
Allows privileged users to masquerade as another user.

Code

function masquerade_toolbar() {
  $items = [
    'masquerade_switch_back' => [
      '#cache' => [
        'contexts' => [
          'session.is_masquerading',
        ],
      ],
    ],
  ];
  if (\Drupal::service('masquerade')
    ->isMasquerading()) {
    $items['masquerade_switch_back'] += [
      '#type' => 'toolbar_item',
      'tab' => [
        '#type' => 'link',
        '#title' => t('Unmasquerade'),
        '#url' => Url::fromRoute('masquerade.unmasquerade'),
      ],
      // Hopefully shows immediately after the username tab.
      '#weight' => 101,
    ];
  }
  return $items;
}