You are here

function civicrm_entity_contact_user_get in CiviCRM Entity 7.2

  • Load user entity according to contact id.

Parameters

$data:

array $options:

$name:

$type:

$info:

Return value

int|null

2 string references to 'civicrm_entity_contact_user_get'
civicrm_entity_entity_property_info_alter in ./civicrm_entity.module
Here we declare Selected CiviCRM entities fields to Drupal.
_civicrm_entity_getproperties in ./civicrm_entity.module
Calculate fields for entities

File

./civicrm_entity.module, line 3680

Code

function civicrm_entity_contact_user_get($data, array $options, $name, $type, $info) {
  if (!module_exists('civicrm') || !function_exists('civicrm_initialize')) {
    return;
  }
  if (!civicrm_initialize()) {
    return;
  }
  $domain_id = civicrm_api('domain', 'getvalue', array(
    'version' => 3,
    'return' => 'id',
    'current_domain' => TRUE,
  ));
  $uf_info = civicrm_api('uf_match', 'getsingle', array(
    'version' => 3,
    'return' => 'uf_id',
    'contact_id' => $data->contact_id,
    'domain_id' => $domain_id,
  ));
  if (!empty($uf_info['uf_id'])) {
    $entity = entity_load('user', array(
      $uf_info['uf_id'],
    ));
    return $entity[$uf_info['uf_id']];
  }
  else {
    return NULL;
  }
}