You are here

trait AccountSwitcherTrait in Tome 8

Shared methods for handling account switching.

Hierarchy

File

modules/tome_sync/src/AccountSwitcherTrait.php, line 10

Namespace

Drupal\tome_sync
View source
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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AccountSwitcherTrait::$accountSwitcher protected property The account switcher.
AccountSwitcherTrait::switchBack protected function Switches the current user back.
AccountSwitcherTrait::switchToAdmin protected function Switches the current user to the admin.