You are here

private function wf_crm_webform_postprocess::createContact in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 7.4 includes/wf_crm_webform_postprocess.inc \wf_crm_webform_postprocess::createContact()

Create a new contact

Parameters

array $contact:

Return value

int

2 calls to wf_crm_webform_postprocess::createContact()
wf_crm_webform_postprocess::createBillingContact in includes/wf_crm_webform_postprocess.inc
Create contact 1 if not already existing (required by contribution.transact)
wf_crm_webform_postprocess::preSave in includes/wf_crm_webform_postprocess.inc
Process webform submission when it is about to be saved. Called by the following hook:

File

includes/wf_crm_webform_postprocess.inc, line 631

Class

wf_crm_webform_postprocess

Code

private function createContact($contact) {
  $params = $contact['contact'][1];

  // CiviCRM API is too picky about this, imho
  $params['contact_type'] = ucfirst($params['contact_type']);
  unset($params['contact_id'], $params['id']);
  if (!isset($params['source'])) {
    $params['source'] = $this->settings['new_contact_source'];
  }

  // If creating individual with no first/last name,
  // set display name and sort_name
  if ($params['contact_type'] == 'Individual' && empty($params['first_name']) && empty($params['last_name'])) {
    $params['display_name'] = $params['sort_name'] = empty($params['nick_name']) ? $contact['email'][1]['email'] : $params['nick_name'];
  }
  $result = wf_civicrm_api('contact', 'create', $params);
  return wf_crm_aval($result, 'id', 0);
}