function opigno_statistics_update_9002 in Opigno statistics 3.x
Set new profile permissions to roles.
File
- ./
opigno_statistics.install, line 90 - Install, update and uninstall functions for the Opigno Statistics module.
Code
function opigno_statistics_update_9002() {
// Set the general permission to view any private profile to admin and user
// manager roles.
try {
$role = \Drupal::entityTypeManager()
->getStorage('user_role')
->load('user_manager');
if ($role instanceof RoleInterface) {
$role
->grantPermission('view any private profile');
$role
->save();
}
} catch (PluginNotFoundException|InvalidPluginDefinitionException|EntityStorageException $e) {
watchdog_exception('opigno_statistics_exception', $e);
}
// Set group permissions.
$permissions = [
'opigno_class-class_manager' => 'view any private profile in class',
'learning_path-user_manager' => 'view any private profile in training',
];
foreach ($permissions as $role_id => $permission) {
try {
$role = \Drupal::entityTypeManager()
->getStorage('group_role')
->load($role_id);
if ($role instanceof GroupRoleInterface) {
$role
->grantPermission($permission);
$role
->save();
}
} catch (PluginNotFoundException|InvalidPluginDefinitionException|EntityStorageException $e) {
watchdog_exception('opigno_statistics_exception', $e);
}
}
}