protected function WebformCivicrmBase::loadBillingAddress in Webform CiviCRM Integration 8.5
Load Billing Address for contact.
2 calls to WebformCivicrmBase::loadBillingAddress()
- WebformAjax::contactAjax in src/
WebformAjax.php - Load one or more contacts via ajax
- WebformCivicrmPreProcess::alterForm in src/
WebformCivicrmPreProcess.php - Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.
File
- src/
WebformCivicrmBase.php, line 84 - Front-end form handler base class.
Class
- WebformCivicrmBase
- Class WebformCivicrmBase
Namespace
Drupal\webform_civicrmCode
protected function loadBillingAddress($cid) {
$utils = \Drupal::service('webform_civicrm.utils');
$billingFields = [
"street_address",
"city",
"postal_code",
"country_id",
"state_province_id",
];
$billingAddress = $utils
->wf_civicrm_api('Address', 'get', [
'contact_id' => $cid,
'location_type_id' => 'Billing',
'return' => $billingFields,
'options' => [
'limit' => 1,
'sort' => 'is_primary DESC',
],
]);
if (!empty($billingAddress['values'])) {
$address = array_pop($billingAddress['values']);
foreach ($address as $key => $value) {
if (in_array($key, $billingFields)) {
$address['billing_address_' . $key] = $value;
}
unset($address[$key]);
}
}
foreach ([
'first_name',
'middle_name',
'last_name',
] as $name) {
$address["billing_address_{$name}"] = $this->loadedContacts[1]['contact'][1][$name] ?? NULL;
}
return $address;
}