Skip to content
Snippets Groups Projects
Commit 13d625d2 authored by Ankit Pathak's avatar Ankit Pathak Committed by Tim Rohaly
Browse files

Issue #3457135 by TR, bharath-kondeti: [10.2] user_roles() and user_role_names() are deprecated

parent d9dae414
No related branches found
No related tags found
1 merge request!38Issue #3457135 "Deprecation fix user roles method"
Pipeline #211401 canceled
......@@ -3,6 +3,8 @@
namespace Drupal\rules\TypedData\Options;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Options provider to return a list of user roles.
......@@ -13,8 +15,10 @@ class RolesOptions extends OptionsProviderBase {
* {@inheritdoc}
*/
public function getPossibleOptions(AccountInterface $account = NULL) {
// Use parameter FALSE to include 'Anonymous'.
$roles = user_role_names(FALSE);
// All roles, including 'Anonymous'.
$roles = array_map(function (RoleInterface $role) {
return $role->label();
}, Role::loadMultiple());
// Sort by the role name.
asort($roles);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment