You are here

AccountSwitcherTrait.php in Tome 8

Namespace

Drupal\tome_sync

File

modules/tome_sync/src/AccountSwitcherTrait.php
View source
<?php

namespace Drupal\tome_sync;

use Drupal\Core\Session\UserSession;

/**
 * Shared methods for handling account switching.
 */
trait AccountSwitcherTrait {

  /**
   * The account switcher.
   *
   * @var \Drupal\Core\Session\AccountSwitcherInterface
   */
  protected $accountSwitcher;

  /**
   * Switches the current user to the admin.
   */
  protected function switchToAdmin() {
    $this->accountSwitcher
      ->switchTo(new UserSession([
      'uid' => 1,
    ]));
  }

  /**
   * Switches the current user back.
   */
  protected function switchBack() {
    $this->accountSwitcher
      ->switchBack();
  }

}

Traits

Namesort descending Description
AccountSwitcherTrait Shared methods for handling account switching.