view_profile_perms.install in View profiles permissions 8
Same filename and directory in other branches
Install, update and uninstall functions for the view_profile_perms module.
File
view_profile_perms.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the view_profile_perms module.
*/
/**
* Update permission name to avoid core permission collision.
*/
function view_profile_perms_update_8600() {
// See https://www.drupal.org/project/view_profiles_perms/issues/2996101
$roles = user_roles(TRUE);
if (count($roles) < 1) {
return t('No roles to update.');
}
$roles_updated = [];
foreach ($roles as $role) {
$role_id = $role
->id();
$old_permission = "access {$role_id} profiles";
if ($role
->hasPermission($old_permission)) {
$role
->revokePermission($old_permission);
$role
->grantPermission("access {$role_id} users profiles");
$role
->save();
$roles_updated[] = $role_id;
}
}
if (empty($roles_updated)) {
return t('No roles needed to be updated.');
}
return t('Updated @count roles: @role_ids', [
'@count' => count($roles_updated),
'@role_ids' => implode(', ', $roles_updated),
]);
}
Functions
Name | Description |
---|---|
view_profile_perms_update_8600 | Update permission name to avoid core permission collision. |