You are here

function role_delegation_user_load in Role Delegation 8

Implements hook_ENTITY_TYPE_load().

File

./role_delegation.module, line 98
Allows admins to grant roles the authority to assign selected roles to users.

Code

function role_delegation_user_load($entities) {

  // This is a workaround for known limitations of computed fields: since they
  // are not stored, they are also not loaded with the user, so values must be
  // manually supplied. This allows us to later determine that an empty field
  // actually means intentional role removals, as opposed to field data not
  // being sent/no access to field.
  // Things may later with https://www.drupal.org/node/2392845.
  foreach ($entities as $user_entity) {
    if ($user_entity
      ->hasField('role_change')) {
      $user_entity
        ->set('role_change', DelegatableRoles::$emptyFieldValue);
    }
  }
}