0

In Drupal 8 I would use the following code.

$current_user = \Drupal::currentUser();
$roles = $current_user->getRoles();

What is the equivalent code I should use in Drupal 7?

1 Answer 1

0

You can access the current user in D7 via the global $user object

global $user;
$roles = $user->roles;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.