private function WebformCivicrmPreProcess::loadParticipants in Webform CiviCRM Integration 8.5
Load participant data for a contact
Parameters
int $c:
1 call to WebformCivicrmPreProcess::loadParticipants()
- 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/
WebformCivicrmPreProcess.php, line 338 - Front-end form pre-processor.
Class
Namespace
Drupal\webform_civicrmCode
private function loadParticipants($c) {
$utils = \Drupal::service('webform_civicrm.utils');
$status_types = $utils
->wf_crm_apivalues('participant_status_type', 'get');
$participants = $utils
->wf_crm_apivalues('participant', 'get', [
'contact_id' => $this->ent['contact'][$c]['id'],
'event_id' => [
'IN' => array_keys($this->events),
],
]);
foreach ($participants as $row) {
$par = [];
// v3 participant api returns some non-standard keys with participant_ prepended
foreach ([
'id',
'event_id',
'role_id',
'status_id',
'campaign_id',
] as $sel) {
$par['participant'][1][$sel] = $row[$sel] = $row[$sel] ?? $row['participant_' . $sel] ?? NULL;
}
$par += $this
->getCustomData($row['id'], 'Participant');
$status = $status_types[$row['status_id']];
foreach ($this->events[$row['event_id']]['form'] as $event) {
if ($event['contact'] == $c) {
// If status has been set by admin or exposed to the form, use it as a filter
if (in_array($status['id'], $event['status_id']) || empty($event['status_id']) && $status['class'] != 'Negative') {
$n = $event['contact'];
$i = $event['num'];
// Support multi-valued form elements as best we can
$event_ids = wf_crm_aval($this->info, "participant:{$n}:participant:{$i}:event_id", []);
if ($event['eid']) {
$event_ids[] = $event['eid'];
}
foreach ($par as $k => $v) {
$this->info['participant'][$n][$k][$i] = $v[1];
}
$this->info['participant'][$n]['participant'][$i]['event_id'] = $event_ids;
}
}
}
}
}