You are here

function view_profile_perms_update_8600 in View profiles permissions 8

Same name and namespace in other branches
  1. 2.0.x view_profile_perms.install \view_profile_perms_update_8600()

Update permission name to avoid core permission collision.

File

./view_profile_perms.install, line 11
Install, update and uninstall functions for the view_profile_perms module.

Code

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),
  ]);
}