diff --git a/lib/Drupal/masquerade/Plugin/block/block/MasqueradeBlock.php b/lib/Drupal/masquerade/Plugin/block/block/MasqueradeBlock.php index 215c664..77027e3 100644 --- a/lib/Drupal/masquerade/Plugin/block/block/MasqueradeBlock.php +++ b/lib/Drupal/masquerade/Plugin/block/block/MasqueradeBlock.php @@ -36,7 +36,7 @@ class MasqueradeBlock extends BlockBase { * Overrides \Drupal\block\BlockBase::blockAccess(). */ public function blockAccess() { - return user_access('masquerade') && !isset($_SESSION['masquerading']); + return user_access('masquerade') && !masquerade_user_is_masquerading(); } /** diff --git a/lib/Drupal/masquerade/Tests/MasqueradeTest.php b/lib/Drupal/masquerade/Tests/MasqueradeTest.php index d1bdd1e..c49efa3 100644 --- a/lib/Drupal/masquerade/Tests/MasqueradeTest.php +++ b/lib/Drupal/masquerade/Tests/MasqueradeTest.php @@ -73,7 +73,7 @@ class MasqueradeTest extends WebTestBase { ), )); $this->assertResponse(200); - $this->assertText('You are now masquerading as ' . $account->name); + $this->assertText('You are now masquerading as ' . $account->label()); // Update the logged in user account. // @see WebTestBase::drupalLogin() @@ -96,7 +96,7 @@ class MasqueradeTest extends WebTestBase { ), )); $this->assertResponse(200); - $this->assertText('You are no longer masquerading as ' . $account->name); + $this->assertText('You are no longer masquerading as ' . $account->label()); // Update the logged in user account. // @see WebTestBase::drupalLogin() diff --git a/masquerade.module b/masquerade.module index 28cb064..e66f926 100644 --- a/masquerade.module +++ b/masquerade.module @@ -184,7 +184,10 @@ function masquerade_user_logout($account) { if (!empty($account->masquerading)) { global $user; $real_user = user_load($user->masquerading); - watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array('%user' => $real_user->name, '%masq_as' => $user->name), WATCHDOG_INFO); + watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array( + '%user' => $real_user->label(), + '%masq_as' => $user->label(), + ), WATCHDOG_INFO, l(t('view'), 'user/' . $user->id())); $query = db_delete('masquerade'); $query->condition('sid', session_id()); @@ -323,7 +326,9 @@ function masquerade_switch_user_validate(User $target_account) { )); } if (!masquerade_user_access($target_account)) { - return t('You are not allowed to masquerade as %name.', array('%name' => $name)); + return t('You are not allowed to masquerade as %name.', array( + '%name' => $target_account->label(), + )); } } @@ -357,9 +362,10 @@ function masquerade_switch_user(User $target_account) { $query->execute(); watchdog('masquerade', 'User %username masqueraded as %target_username.', array( + // Use "name" here because $user object could not be fully initialized. '%username' => $user->name, - '%target_username' => $target_account->name, - ), WATCHDOG_INFO); + '%target_username' => $target_account->label(), + ), WATCHDOG_INFO, l(t('view'), 'user/' . $target_account->id())); drupal_set_message(t('You are now masquerading as !user.', array( '!user' => theme('username', array('account' => $target_account)), ))); @@ -423,9 +429,10 @@ function masquerade_switch_back() { module_invoke_all('user_login', $user); watchdog('masquerade', 'User %username stopped masquerading as %old_username.', array( - '%username' => $user->name, + '%username' => $user->label(), + // Use "name" here because $user object could not be fully initialized. '%old_username' => $old_user->name, - ), WATCHDOG_INFO); + ), WATCHDOG_INFO, l($user->label(), 'user/' . $user->id())); } /**