1 user.install | user_update_1008() |
Update views that used the old role ID handlers to use role name instead.
Related topics
File
- core/
modules/ user/ user.install, line 478 - Install, update and uninstall functions for the user module.
Code
function user_update_1008() {
$configs = config_get_names_with_prefix('views.view.');
foreach ($configs as $config_name) {
$config = config($config_name);
$view_data = $config->get();
$changed = FALSE;
foreach ($view_data['display'] as $display_name => $display_data) {
foreach (array('fields', 'filters') as $handler_type) {
if (isset($display_data['display_options'][$handler_type])) {
foreach ($display_data['display_options'][$handler_type] as $handler_key => $handler_data) {
// Change users_roles.rid to users_roles.role.
if ($handler_data['table'] === 'users_roles' && $handler_data['field'] === 'rid') {
$view_data['display'][$display_name]['display_options'][$handler_type][$handler_key]['field'] = 'role';
$changed = TRUE;
}
// Change role_permission.permission to users_roles.permissions.
if ($handler_data['table'] === 'role_permission' && $handler_data['field'] === 'permission') {
$view_data['display'][$display_name]['display_options'][$handler_type][$handler_key]['table'] = 'users_roles';
$view_data['display'][$display_name]['display_options'][$handler_type][$handler_key]['field'] = 'permissions';
$changed = TRUE;
}
}
}
}
}
if ($changed) {
$config->setData($view_data);
$config->save();
}
}
}