Skip to content

Commit

Permalink
Merge pull request #43 from omarabuhussein/fix-address-save
Browse files Browse the repository at this point in the history
Fix Address fields not being updated
  • Loading branch information
colemanw authored Aug 4, 2016
2 parents c32a046 + 04450ed commit a17ccef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
15 changes: 15 additions & 0 deletions includes/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,21 @@ function wf_crm_location_fields() {
return array('address', 'email', 'phone', 'website', 'im');
}

/**
* These are the address fields this module supports
*
* @return array
*/
function wf_crm_address_fields() {
return array(
'street_address',
'city',
'state_province_id',
'country_id',
'postal_code'
);
}

/**
* Returns a count of children of a webform component
*
Expand Down
38 changes: 36 additions & 2 deletions includes/wf_crm_webform_postprocess.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,6 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
$index = 1;
$entityTypeIdIndex = $entity.'_type_id';
$entity = $entity == 'website' ? 'url' : $entity; // for website only
$submittedLocationValues = self::unsetEmptyValueIndexes($submittedLocationValues, $entity);

foreach ($existingLocationValues as $eValue) {
$existingLocationTypeId = $entity != 'url' ? $eValue['location_type_id'] : NULL;
Expand All @@ -2227,6 +2226,24 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {

$reorderedArray[$index][$entity] = $eValue[$entity];

// address field contain many sub fields and should be handled differently
if ($entity != 'address') {
$submittedLocationValues = self::unsetEmptyValueIndexes($submittedLocationValues, $entity);
$reorderedArray[$index][$entity] = $eValue[$entity];
}
else {
foreach (wf_crm_address_fields() as $field) {
$reorderedArray[$index][$field] = isset($eValue[$field]) ? $eValue[$field] : '';
}
// handle supplemental addresses
$subAddressIndex = 1;
$subAddField = 'supplemental_address_' . $subAddressIndex;
while(isset($eValue[$subAddField])) {
$reorderedArray[$index][$subAddField] = $eValue[$subAddField];
$subAddField = 'supplemental_address_' . ++$subAddressIndex;
}
}

foreach ($submittedLocationValues as $key => $sValue) {
$sLocationTypeId = isset($sValue['location_type_id']) ? $sValue['location_type_id'] : NULL;
$sEntityTypeId = isset($sValue[$entityTypeIdIndex]) ? $sValue[$entityTypeIdIndex] : NULL;
Expand All @@ -2237,7 +2254,24 @@ class wf_crm_webform_postprocess extends wf_crm_webform_base {
||
($existingLocationTypeId == $sLocationTypeId && $existingEntityTypeId == $sEntityTypeId)) {

$reorderedArray[$index][$entity] = $sValue[$entity];
// address field contain many sub fields and should be handled differently
if ($entity != 'address') {
$reorderedArray[$index][$entity] = $sValue[$entity];
}
else {
foreach (wf_crm_address_fields() as $field) {
if (isset($sValue[$field])) {
$reorderedArray[$index][$field] = $sValue[$field];
}
}
// handle supplemental addresses
$subAddressIndex = 1;
$subAddField = 'supplemental_address_' . $subAddressIndex;
while(isset($sValue[$subAddField])) {
$reorderedArray[$index][$subAddField] = $sValue[$subAddField];
$subAddField = 'supplemental_address_' . ++$subAddressIndex;
}
}
unset($submittedLocationValues[$key]);
}
}
Expand Down

0 comments on commit a17ccef

Please sign in to comment.