You are here

function cas_user_role_delete in CAS 8

Same name and namespace in other branches
  1. 2.x cas.module \cas_user_role_delete()

Implements hook_ENTITY_TYPE_delete().

File

./cas.module, line 38
Provides CAS authentication for Drupal.

Code

function cas_user_role_delete(RoleInterface $role) {
  $config = \Drupal::configFactory()
    ->getEditable('cas.settings');
  $auto_assigned_roles = $config
    ->get('user_accounts.auto_assigned_roles');
  $array_key = array_search($role
    ->id(), $auto_assigned_roles, TRUE);
  if ($array_key) {

    // Remove the role from the auto-assigned roles.
    unset($auto_assigned_roles[$array_key]);
    $config
      ->set('user_accounts.auto_assigned_roles', $auto_assigned_roles)
      ->save();
  }
}