function UserSession::hasRole

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Session/UserSession.php \Drupal\Core\Session\UserSession::hasRole()

Whether a user has a certain role.

@todo in Drupal 11, add method to Drupal\Core\Session\AccountInterface.

Parameters

string $rid: The role ID to check.

Return value

bool Returns TRUE if the user has the role, otherwise FALSE.

See also

https://www.drupal.org/node/3228209

File

core/lib/Drupal/Core/Session/UserSession.php, line 117

Class

UserSession
An implementation of the user account interface for the global user.

Namespace

Drupal\Core\Session

Code

public function hasRole(string $rid) : bool {
    return in_array($rid, $this->getRoles(), TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.