Role migration

Last updated on
30 April 2025

Roles are migrated using a distinct class, rather than implicitly as part of a user migration.

  1. Instantiate the appropriate role migration class
  2. pass the machine_name of the role migration as the value for the 'role_migration' key of the array used to register your user migration. For example:
      $user_arguments = $common_arguments + array(
        'description' => t('Migration of users from Drupal 6'),
        'machine_name' => 'user',
        'class_name' => 'MyUserMigrationClass',
        'role_migration' => 'role_migration_machine_name',
      );
    
  3. add
        $this->addFieldMapping('roles', 'roles')
          ->sourceMigration('role_migration_machine_name');
    

    in the constructor for the User migration class

  4. and users will be assigned the correct roles.

    Role migrations support one argument in addition to the common arguments:

  • role_mappings: An array keyed by the source role name, with a destination role name as the value. When importing roles, instead of the source role name being created on the destination, its role ID will map to the specified destination role's ID.
$role_arguments = $common_arguments + array(
  'machine_name' => 'ExampleRole',
  'description' => t('Import Drupal 6 roles'),
  'role_mappings' => array(
    'Fan Club' => 'fan club member',
  ),
);
Migration::registerMigration('DrupalRole6Migration', 
  $role_arguments['machine_name'], $role_arguments);

Tip: you can find the role names of a D5, D6, or D7 website in the "role" table in the database.

Help improve this page

Page status: Not set

You can: