function user_update_8017

Migrate user roles into configuration.

Related topics

File

drupal/core/modules/user/user.install, line 1035
Install, update and uninstall functions for the user module.

Code

function user_update_8017() {
  $uuid = new Uuid();
  $roles = db_select('role', 'r')
    ->fields('r')
    ->execute()
    ->fetchAll();
  foreach ($roles as $role) {
    config('user.role.' . $role->rid)
      ->set('id', $role->rid)
      ->set('uuid', $uuid
      ->generate())
      ->set('label', $role->name)
      ->set('weight', $role->weight)
      ->set('langcode', Language::LANGCODE_NOT_SPECIFIED)
      ->save();
  }
}