function user_role_names

Same name in other branches
  1. 9 core/modules/user/user.module \user_role_names()
  2. 8.9.x core/modules/user/user.module \user_role_names()

Retrieves the names of roles matching specified conditions.

Parameters

bool $members_only: (optional) Set this to TRUE to exclude the 'anonymous' role. Defaults to FALSE.

string|null $permission: (optional) A string containing a permission. If set, only roles containing that permission are returned. Defaults to NULL, which returns all roles.

Return value

array An associative array with the role id as the key and the role name as value.

Deprecated

in drupal:10.2.0 and is removed from drupal:11.0.0. Use \Drupal\user\Entity\Role::loadMultiple() and, if necessary, an inline implementation instead.

See also

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

File

core/modules/user/user.module, line 845

Code

function user_role_names($members_only = FALSE, $permission = NULL) {
    @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use \\Drupal\\user\\Entity\\Role::loadMultiple() and, if necessary, an inline implementation instead. See https://www.drupal.org/node/3349759', E_USER_DEPRECATED);
    return array_map(function ($item) {
        return $item->label();
    }, user_roles($members_only, $permission));
}

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