private function WebformCivicrmPostProcess::createContact in Webform CiviCRM Integration 8.5
Create a new contact
Parameters
array $contact:
Return value
int
2 calls to WebformCivicrmPostProcess::createContact()
- WebformCivicrmPostProcess::createBillingContact in src/
WebformCivicrmPostProcess.php - Create contact 1 if not already existing (required by contribution.transact)
- WebformCivicrmPostProcess::preSave in src/
WebformCivicrmPostProcess.php - Process webform submission when it is about to be saved. Called by the following hook:
File
- src/
WebformCivicrmPostProcess.php, line 707 - Front-end form validation and post-processing.
Class
Namespace
Drupal\webform_civicrmCode
private function createContact($contact) {
$params = $contact['contact'][1];
$utils = \Drupal::service('webform_civicrm.utils');
// 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 = $utils
->wf_civicrm_api('contact', 'create', $params);
return wf_crm_aval($result, 'id', 0);
}