You are here

public function RequestSubscriber::onKernelRequest in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php \Drupal\crm_core_user_sync\EventSubscriber\RequestSubscriber::onKernelRequest()

Kernel request event handler.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: Response event.

File

modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php, line 71

Class

RequestSubscriber
CRM Core User Synchronization event subscriber.

Namespace

Drupal\crm_core_user_sync\EventSubscriber

Code

public function onKernelRequest(GetResponseEvent $event) {
  if ($this->currentUser
    ->isAuthenticated()) {
    $config = $this->configFactory
      ->get('crm_core_user_sync.settings');
    if ($config
      ->get('contact_load')) {
      $individual_id = $this->relationService
        ->getUserIndividualId($this->currentUser
        ->id());
      if ($individual_id) {
        $individual = $this->entityTypeManager
          ->getStorage('crm_core_individual')
          ->load($individual_id);
        $account = $this->currentUser
          ->getAccount();
        $account->crm_core['contact'] = $individual;
        $this->currentUser
          ->setAccount($account);
      }
    }
  }
}