How to check if a user has a role in Drupal 8 and Drupal 9

In Drupal 8/9, check if a user has a role by using the following snippet.
copy-icon

Comments

Authors

Read Next