Quantcast
Channel: Active questions tagged users - Drupal Answers
Viewing all articles
Browse latest Browse all 468

Get user role by user field

$
0
0

how can I access to my user role thanks to my user custom field ?

I have an user field called "custField" and it's value (example : 123456). I need to check all users that have "123456" as value.

Then, I need to check if this user as the role "director".

But I don't know how to access role thanks to another field.

EDIT :

See this loop :

foreach($retraitDoublons as $valUnique){  $users = \Drupal::entityTypeManager()->getStorage('user')    ->loadByProperties(['field_custVal' => $valUnique]);  $user = reset($users);  $user_has_role = $user && $user->hasRole('directeur_cr_');  dump($user);  dump($user_has_role);  echo $valUnique . "<hr>";}

Viewing all articles
Browse latest Browse all 468

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>