- Role IDs no longer exist; they are replaced by new role (machine) names.
ridcolumn in the
users_rolestable is now a varchar
- Old role "names" are now "labels".
DRUPAL_ANONYMOUS_RIDis now renamed to
BACKDROP_ANONYMOUS_ROLEand its value is
'anonymous'instead of the integer 1.
DRUPAL_AUTHENTICATED_RIDis now renamed to
BACKDROP_AUTHENTICATED_ROLEand its value is
'authenticated'instead of the integer 2.
user_role_load()now takes the role name as its argument instead of role ID.
user_role_load_by_name()has been removed, since all roles are loaded by names now.
user_roles()now returns an array of
machine_name => labelvalues, instead of
role_id => role_names.
user_roles()now has a 3rd argument
$full_objectsfor loading complete user role objects, instead of returning just labels.
- The structure of a role object is changed to accommodate the new machine names and labels.
$user_role->rid = 5;
$user_role->name = 'my role name';
$user_role->name = 'my_role_name';
$user_role->label = 'My role label';
- The list of roles in
$user->rolesis now an unindexed array of user role names, rather than IDs and names.
$user->roles = array(
2 => 'authenticated user',
3 => 'administrator',
$user->roles = array('authenticated', 'administrator');
This means that checking user roles is now done by checking the value of the roles array, rather than the keys:
$has_role = isset($user->roles[BACKDROP_AUTHENTICATED_RID]);
Upgrading from Drupal 7
When upgrading from Drupal 7, Backdrop names the new configuration file for each role based on the ID which the role had in Drupal 7. So a role with RID = 3 will get a config file named
user.role.3.json, and the name key in the config file will be
Also, the output of
user_roles() on an upgraded Drupal 7 site will -for example- be:
'anonymous' => 'Anonymous',
'authenticated' => 'Authenticated',
3 => 'Administrator',
4 => 'My custom role',
So previous roles IDs are preserved that way, in case any contrib or custom module requires to use the RIDs to provide an upgrade path.