By editor, 23 May, 2018 Question How to switch user sessions using account switcher (account_switcher) service ? Example: use Drupal\Core\Session\UserSession; // // Call the account switcher service $accountSwitcher = \Drupal::service('account_switcher'); // Switch to the admin user $accountSwitcher->switchTo(new \Drupal\Core\Session\UserSession(['uid' => 1])); // // Your Code Here... // // Switch back to old session. $accountSwitcher->switchBack(); Tags Drupal 8 Code Services Comments You must have JavaScript enabled to use this form. Your name Subject Comment About text formats Plain text No HTML tags allowed. Lines and paragraphs break automatically. Web page addresses and email addresses turn into links automatically.
Comments