You are here

function restrict_by_ip_user_load in Restrict Login or Role Access by IP Address 8.4

When a user entity is loaded, remove any roles that are restricted based on IP whitelists.

Parameters

\Drupal\user\Entity\User[] $users: Array of user entities keyed by entity ID.

File

./restrict_by_ip.module, line 179
Restrict logins or roles to whitelisted IP addresses.

Code

function restrict_by_ip_user_load($users) {
  $role_firewall = \Drupal::service('restrict_by_ip.role_firewall');
  $remove_roles = $role_firewall
    ->rolesToRemove();
  foreach ($users as $user) {
    foreach ($remove_roles as $role) {
      $user
        ->removeRole($role);
    }
  }
}