function RoleExpireApiService::roleExpirationCanBeDeletedOnUserEditSave in Role Expire 8
Same name and namespace in other branches
- 2.x src/RoleExpireApiService.php \Drupal\role_expire\RoleExpireApiService::roleExpirationCanBeDeletedOnUserEditSave()
On user form save we decide whether to delete role expiration or not.
Parameters
string $rid: Role ID.
Return value
bool Return TRUE if expiration for role can be deleted.
File
- src/
RoleExpireApiService.php, line 350
Class
- RoleExpireApiService
- Class RoleExpireApiService.
Namespace
Drupal\role_expireCode
function roleExpirationCanBeDeletedOnUserEditSave($rid) {
$currentUser = \Drupal::currentUser();
if ($currentUser
->hasPermission('administer permissions')) {
/*
* User with this permission won't be limited by roleassign and
* role_delegation modules.
*/
return TRUE;
}
if ($this->moduleHandler
->moduleExists('roleassign')) {
if ($currentUser
->hasPermission('assign roles')) {
$roleassign_config = $this->config
->get('roleassign.settings')
->get('roleassign_roles');
$assignable_roles = array_values($roleassign_config);
if (!in_array($rid, $assignable_roles)) {
/*
* Current user doesn't have permission to assign this role. So,
* we shouldn't delete it's expiration time only because he/she
* doesn't see it.
*/
return FALSE;
}
}
}
if ($this->moduleHandler
->moduleExists('role_delegation')) {
if (!$currentUser
->hasPermission(sprintf('assign %s role', $rid))) {
/*
* Current user doesn't have permission to assign this role. So,
* we shouldn't delete it's expiration time only because he/she
* doesn't see it.
*/
return FALSE;
}
}
return TRUE;
}