protected function WebformCivicrmBase::matchLocationTypes in Webform CiviCRM Integration 8.5
Organize values according to location types
Parameters
integer $c:
string $ent:
array $values:
Return value
array $reorderedArray
1 call to WebformCivicrmBase::matchLocationTypes()
- WebformCivicrmBase::reorderByLocationType in src/
WebformCivicrmBase.php - Reorder returned results according to settings chosen in wf_civicrm backend
File
- src/
WebformCivicrmBase.php, line 369 - Front-end form handler base class.
Class
- WebformCivicrmBase
- Class WebformCivicrmBase
Namespace
Drupal\webform_civicrmCode
protected function matchLocationTypes($c, $ent, &$values) {
// create temporary settings array to include 'user-select' fields
// on the right place in array
$settingsArray = $this
->add_user_select_field_placeholder($ent, $this->settings['data']['contact'][$c]);
$userSelectIndex = 0;
// Go through the array and match up locations by type
// Put placeholder 'user-select' where location_type_id is empty for second pass
foreach ($settingsArray[$ent] as $setting) {
$valueFound = false;
foreach ($values as $key => $value) {
if (in_array($ent, [
'address',
'email',
]) && $value['location_type_id'] == $setting['location_type_id'] || $value['location_type_id'] == $setting['location_type_id'] && (!isset($setting[$ent . '_type_id']) || $value[$ent . '_type_id'] == $setting[$ent . '_type_id'])) {
$reorderedArray[$key] = $value;
$valueFound = true;
unset($values[$key]);
break;
}
else {
if (empty($setting['location_type_id'])) {
$valueFound = true;
$reorderedArray['us' . $userSelectIndex] = 'user-select';
$userSelectIndex++;
break;
}
}
}
// always keep number of returned values equal to chosen settings
// if value is not found then set an empty array
if (!$valueFound) {
$reorderedArray[] = [];
}
}
return $reorderedArray;
}