Role migration
Last updated on
30 April 2025
Roles are migrated using a distinct class, rather than implicitly as part of a user migration.
- Instantiate the appropriate role migration class
- 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', ); - add
$this->addFieldMapping('roles', 'roles') ->sourceMigration('role_migration_machine_name');in the constructor for the User migration class
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:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion