You are here

function civicrm_entity_user_contact_get in CiviCRM Entity 7

Same name and namespace in other branches
  1. 7.2 civicrm_entity.module \civicrm_entity_user_contact_get()

Load contact entity according to user id.

Parameters

$data:

array $options:

$name:

$type:

$info:

Return value

null

1 string reference to 'civicrm_entity_user_contact_get'
civicrm_entity_entity_property_info_alter in ./civicrm_entity.module
Here we declare Selected CiviCRM entities fields to Drupal.

File

./civicrm_entity.module, line 969
Implement CiviCRM entities as a Drupal Entity.

Code

function civicrm_entity_user_contact_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,
  ));
  $contact = civicrm_api('uf_match', 'getsingle', array(
    'version' => 3,
    'return' => 'contact_id',
    'uf_id' => $data->uid,
    'domain_id' => $domain_id,
  ));
  if (!empty($contact['contact_id'])) {
    $entity = entity_load('civicrm_contact', array(
      $contact['contact_id'],
    ));
    return $entity[$contact['contact_id']];
  }
  else {
    return NULL;
  }
}