function UserSession::getRoles

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Session/UserSession.php \Drupal\Core\Session\UserSession::getRoles()
  2. 10 core/lib/Drupal/Core/Session/UserSession.php \Drupal\Core\Session\UserSession::getRoles()
  3. 11.x core/lib/Drupal/Core/Session/UserSession.php \Drupal\Core\Session\UserSession::getRoles()

Overrides AccountInterface::getRoles

1 call to UserSession::getRoles()
UserSession::hasPermission in core/lib/Drupal/Core/Session/UserSession.php
Checks whether a user has a certain permission.

File

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

Class

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

Namespace

Drupal\Core\Session

Code

public function getRoles($exclude_locked_roles = FALSE) {
    $roles = $this->roles;
    if ($exclude_locked_roles) {
        $roles = array_values(array_diff($roles, [
            AccountInterface::ANONYMOUS_ROLE,
            AccountInterface::AUTHENTICATED_ROLE,
        ]));
    }
    return $roles;
}

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