• Role IDs no longer exist; they are replaced by new role (machine) names.
  • The rid column in the users_roles table is now a varchar role column.
  • Old role "names" are now "labels".
  • DRUPAL_ANONYMOUS_RID is now renamed to BACKDROP_ANONYMOUS_ROLE and its value is 'anonymous' instead of the integer 1.
  • DRUPAL_AUTHENTICATED_RID is now renamed to BACKDROP_AUTHENTICATED_ROLE and 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 deprecated, since all roles are loaded by names now.
  • user_roles() now returns an array of machine_name => label values, instead of role_id => role_names.
  • user_roles() now has a 3rd argument $full_objects for 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.

    Drupal 7:

    $user_role->rid = 5;
    $user_role->name = 'my role name';

    Backdrop:

    $user_role->name = 'my_role_name';
    $user_role->label = 'My role label';
  • The list of roles in $user->roles is now an unindexed array of user role names, rather than IDs and names.
    Drupal 7:
    $user->roles = array(
      2 => 'authenticated user',
      3 => 'administrator',
    );

    Backdrop:
    $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:

    Drupal 7:
    $has_role = isset($user->roles[BACKDROP_AUTHENTICATED_RID]);

    Backdrop:
    $has_role = in_array(BACKDROP_AUTHENTICATED_ROLE, $user->roles);

The identifiers for the Anonymous and Authenticated roles have been changed in Backdrop.

Example Drupal 7 output of user_roles():

array(
  1 => 'Anonymous',
  2 => 'Authenticated',
  3 => 'Administrator',
  4 => 'My custom role',
);

Example Backdrop output of user_roles() after upgrade:

array(
  'anonymous' => 'Anonymous',
  'authenticated' => 'Authenticated',
  '3' => 'Administrator',
  '4' => 'My custom role',
);

Upgrading from Drupal 7

When upgrading from Drupal 7, Backdrop switches the identifiers for anonymous users (previously 1) to anonymous and for authenticated users (previously 2) to authenticated.

All other machine names for roles are based on the ID which the role used 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 name: 3.

With the exception of roles 1, and 2, roles IDs are preserved so that any module depending on the RIDs can have a smooth upgrade path.

Upgrade code examples

For those modules that relied on the role IDs in Drupal 7, they will need include something like the following in one of the update hooks:

    // Ensure default role identifiers are correct.
    if ($row->rid == 1) {
      $role_data['name'] = 'anonymous';
    }
    if ($row->rid == 2) {
      $role_data['name'] = 'authenticated';
    }

This code will need to be executed before the role IDs are removed from Backdrop, and that can be done by implementing hook_update_dependencies() as follows:

/**
* Implements hook_update_dependencies().
*/
function mymodule_update_dependencies() {
  // Indicate that the mymodule_update_1001() function provided by this module
  // must run before the user_update_1007() function from the user module.
  $dependencies['user'][1007] = array(
    'mymodule' => 1001,
  );
  return $dependencies;
}
Introduced in branch: 
1.0.x
Introduced in version: 
1.0.0
Impacts: 
Module developers