function getRoleIdWithMaxWeight in Form Mode Control 8
Choose the maximum weight for current user 's role.
Return value
int|string
1 call to getRoleIdWithMaxWeight()
File
- ./
form_mode_control.module, line 161
Code
function getRoleIdWithMaxWeight() {
//Get all roles.
$all_id_roles = array_keys(Role::loadMultiple());
// Get role of current user logged.
$roles_current_user = \Drupal::currentUser()
->getRoles();
$roles_intersect = array_intersect($all_id_roles, $roles_current_user);
$max_weight = 0;
$id_role_max_weight = "role";
foreach ($roles_intersect as $id_role) {
if (Role::loadMultiple()[$id_role]
->getWeight() > $max_weight) {
//
$max_weight = Role::loadMultiple()[$id_role]
->getWeight();
$id_role_max_weight = $id_role;
}
}
return $id_role_max_weight;
}