From d067d7b00ab98b7e54f14980984a976e3d394f5e Mon Sep 17 00:00:00 2001 From: Darren Oh <2293701+darrenoh@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:50:46 -0500 Subject: [PATCH] Fix format of user roles array --- src/User/GlobalUser.php | 3 ++- tests/data/menu_example/menu_example.module | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/User/GlobalUser.php b/src/User/GlobalUser.php index 3736502..c2dd1c1 100644 --- a/src/User/GlobalUser.php +++ b/src/User/GlobalUser.php @@ -5,6 +5,7 @@ namespace Retrofit\Drupal\User; use Drupal\Core\Session\AccountInterface; +use Drupal\user\Entity\Role; final class GlobalUser implements AccountInterface { @@ -85,7 +86,7 @@ public function getLastAccessedTime() public function __get(string $name) { return match ($name) { - 'roles' => $this->getRoles(), + 'roles' => array_combine($this->getRoles(), array_map([Role::class, 'load'], $this->getRoles())), 'name' => $this->getAccountName(), default => null, }; diff --git a/tests/data/menu_example/menu_example.module b/tests/data/menu_example/menu_example.module index 6d23a86..da29f95 100644 --- a/tests/data/menu_example/menu_example.module +++ b/tests/data/menu_example/menu_example.module @@ -377,7 +377,7 @@ function menu_example_permission() { * True if the acting user has the role specified. */ function menu_example_custom_access($role_name) { - $access_granted = in_array($role_name, $GLOBALS['user']->roles); + $access_granted = array_key_exists($role_name, $GLOBALS['user']->roles); return $access_granted; }