Commit 1b97ba13 authored by webchick's avatar webchick

Issue #2213899 by dawehner, joelpittet: Remove global $user wherever possible...

Issue #2213899 by dawehner, joelpittet: Remove global $user wherever possible (outside bootstrap and authentication) Round 2.
parent 6227e3aa
......@@ -1165,14 +1165,8 @@ protected function drupalStaticReset($name = NULL) {
* @return \Drupal\Core\Session\AccountInterface
*/
protected function currentUser() {
if (!$this->currentUser) {
if (\Drupal::hasService('current_user')) {
$this->currentUser = \Drupal::currentUser();
}
else {
global $user;
$this->currentUser = $user;
}
if (!$this->currentUser && \Drupal::hasService('current_user')) {
$this->currentUser = \Drupal::currentUser();
}
return $this->currentUser;
}
......
......@@ -43,7 +43,7 @@ public function testHandlers() {
$account = $this->drupalCreateUser();
$this->drupalLogin($account);
$GLOBALS['user'] = $account;
\Drupal::currentUser()->setAccount($account);
db_insert('history')
->fields(array(
......
......@@ -29,17 +29,16 @@ public function test_plugin_argument_default_current_user() {
// Switch the user, we have to check the global user too, because drupalLogin is only for the simpletest browser.
$this->drupalLogin($account);
global $user;
$admin = $user;
$admin = \Drupal::currentUser();
$session_manager = \Drupal::service('session_manager')->disable();
$user = $account;
\Drupal::currentUser()->setAccount($account);
$view = Views::getView('test_plugin_argument_default_current_user');
$view->initHandlers();
$this->assertEqual($view->argument['null']->getDefaultArgument(), $account->id(), 'Uid of the current user is used.');
// Switch back.
$user = $admin;
\Drupal::currentUser()->setAccount($admin);
$session_manager->enable();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment