Mistraë
Mistraë

Reputation: 337

Get Drupal 8 Roles label

I'm loading a user to get his roles, but I only get the role machine name. I found the way to load those roles:

$roles = Role::loadMultiple($user->getRoles());

but now I need to get the labels of those roles.

Thanks.

Upvotes: 3

Views: 2571

Answers (1)

GregCube
GregCube

Reputation: 121

foreach ($roles as $role) {
  $label = $role->label();
}

Upvotes: 4

Related Questions