You are here

function janrain_capture_mapping_janrain_capture_user_authenticated in Janrain Registration 8

Implements hook_janrain_capture_user_authenticated().

File

janrain_capture_mapping/janrain_capture_mapping.module, line 15
Janrain Capture Mapping module file.

Code

function janrain_capture_mapping_janrain_capture_user_authenticated(JanrainUserProfile $profile, UserInterface $user, bool $is_new) : void {
  $profile_uuid = $profile
    ->getUuid();
  $data = \Drupal::service('config.typed')
    ->get('janrain_capture.mapping')
    ->getValue();
  if (isset($data['mapping']) && $user
    ->uuid() === $profile_uuid) {
    foreach ($data['mapping'] as $mapping) {
      try {
        $user
          ->set($mapping['field'], $profile->{$mapping['capture_field']});
      } catch (Exception $e) {
        watchdog_exception('update', $e);
      }
    }
    $user
      ->save();
  }
}