private function WebformCivicrmPostProcess::getNameForMultiValueFields in Webform CiviCRM Integration 8.5
Retrieve name for multi-value custom fields.
For edit mode, update the $name key to 'custom_<fieldID>_<existing_value_id>.
If webform is configured to only "insert" new values, modify the params in the format of custom_<fieldID>_-1, custom_<fieldID>_-2, etc.
Parameters
bool $multivaluesCreateMode:
string $name:
string $table:
int $c:
int $n:
Return value
string $name
2 calls to WebformCivicrmPostProcess::getNameForMultiValueFields()
- WebformCivicrmPostProcess::fillContactRefs in src/
WebformCivicrmPostProcess.php - Recursive function to fill ContactRef fields with contact IDs
- WebformCivicrmPostProcess::fillDataFromSubmission in src/
WebformCivicrmPostProcess.php - Fill data array with submitted form values
File
- src/
WebformCivicrmPostProcess.php, line 2802 - Front-end form validation and post-processing.
Class
Namespace
Drupal\webform_civicrmCode
private function getNameForMultiValueFields($multivaluesCreateMode, $name, $table, $c, $n) : string {
// Multi value fields are already saved while creating the billing contact.
if ($c == 1 && !empty($this->billing_contact)) {
return '';
}
$existingValue = NULL;
if (empty($multivaluesCreateMode) && !empty($this->existing_contacts[$c])) {
$existingValue = $this
->getCustomData($this->existing_contacts[$c], NULL, FALSE)[$table] ?? NULL;
if (!empty($existingValue) && is_array($existingValue)) {
$existingValue = key(array_slice($existingValue, $n - 1, 1, TRUE));
if (!empty($existingValue)) {
return "{$name}_{$existingValue}";
}
}
}
// No existing value found, insert a new value.
if (empty($existingValue)) {
return "{$name}_-{$n}";
}
return $name;
}