Skip to content

Commit

Permalink
Fix format of user roles array
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenoh committed Nov 20, 2023
1 parent 6fe1d79 commit d067d7b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/User/GlobalUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Retrofit\Drupal\User;

use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;

final class GlobalUser implements AccountInterface
{
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion tests/data/menu_example/menu_example.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d067d7b

Please sign in to comment.