Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Drupal 8 Roles label

Tags:

roles

drupal-8

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.

like image 303
Leeroy Avatar asked Mar 09 '26 16:03

Leeroy


1 Answers

foreach ($roles as $role) {
  $label = $role->label();
}
like image 162
GregCube Avatar answered Mar 12 '26 16:03

GregCube



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!