You are here

userswitch.module in User Switch 8

Contains userswitch.module.

File

userswitch.module
View source
<?php

/**
 * @file
 * Contains userswitch.module.
 */
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function userswitch_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.userswitch':
      return t('The User Switch module allows the user to switch accounts.');
  }
}

/**
 * Implements hook_toolbar().
 */
function userswitch_toolbar() {
  $items = [];
  if (\Drupal::service('userswitch')
    ->isSwitchUser()) {
    $items['user_switch_back'] = [
      '#type' => 'toolbar_item',
      'tab' => [
        '#type' => 'link',
        '#title' => t('Back to Account'),
        '#url' => Url::fromRoute('userswitch.backuser.switch'),
        '#attributes' => [
          'class' => [
            'toolbar-icon',
            'toolbar-icon-escape-admin',
          ],
        ],
      ],
      '#weight' => -20,
    ];
  }
  return $items;
}

Functions

Namesort descending Description
userswitch_help Implements hook_help().
userswitch_toolbar Implements hook_toolbar().