Issue #3057674 by markcarver, gorkagr: Error: Call to a member function id()...

Issue #3057674 by markcarver, gorkagr: Error: Call to a member function id() on null in Bootstrap::isAdmin()
Signed-off-by: markcarver's avatarMark Carver <mark.carver@me.com>
parent 0cabdc1c
......@@ -14,9 +14,8 @@ use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Markup;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
......@@ -1234,21 +1233,27 @@ class Bootstrap {
/**
* Checks whether a user is an administrator.
*
* @param \Drupal\user\UserInterface $user
* Optional. A specific user to check. If not set, the currently logged in
* user will be used.
* @param \Drupal\Core\Session\AccountInterface $account
* Optional. A specific account to check. If not set, the currently logged
* in user account will be used.
*
* @return bool
* TRUE or FALSE
*/
public static function isAdmin(UserInterface $user = NULL) {
public static function isAdmin(AccountInterface $account = NULL) {
static $admins = [];
$user = $user ?: User::load(\Drupal::currentUser()->id());
$uid = (int) $user->id();
if (!isset($admins[$uid])) {
$admins[$uid] = $user->hasPermission('access administration pages');
// Use the currently logged in user if no account was explicitly specified.
if (!$account) {
$account = \Drupal::currentUser();
}
$id = (int) $account->id();
if (!isset($admins[$id])) {
$admins[$id] = $account->hasPermission('access administration pages');
}
return $admins[$uid];
return $admins[$id];
}
/**
......
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