function Utils::wf_crm_user_cid in Webform CiviCRM Integration 8.5
Lookup a uf ID from contact ID or vice-versa With no arguments passed in, this function will return the contact_id of the current logged-in user
Parameters
$id: (optional) uf or contact ID - defaults to current user
$type: (optional) what type of ID is supplied - defaults to user id
Return value
int|null
Overrides UtilsInterface::wf_crm_user_cid
File
- src/
Utils.php, line 519 - Webform CiviCRM module's common utility functions.
Class
Namespace
Drupal\webform_civicrmCode
function wf_crm_user_cid($id = NULL, $type = 'uf') {
static $current_user = NULL;
if (!$id) {
if ($current_user !== NULL) {
return $current_user;
}
$id = $user_lookup = \Drupal::currentUser()
->id();
}
if (!$id || !is_numeric($id)) {
return NULL;
}
// Lookup current domain for multisite support
static $domain = 0;
if (!$domain) {
$domain = $this
->wf_civicrm_api('domain', 'get', [
'current_domain' => 1,
'return' => 'id',
]);
$domain = wf_crm_aval($domain, 'id', 1);
}
$result = $this
->wf_crm_apivalues('uf_match', 'get', [
$type . '_id' => $id,
'domain_id' => $domain,
'sequential' => 1,
]);
if ($result) {
if (!empty($user_lookup)) {
$current_user = $result[0]['contact_id'];
}
return $type == 'uf' ? $result[0]['contact_id'] : $result[0]['uf_id'];
}
}