private function WebformCivicrmPreProcess::findExistingCases in Webform CiviCRM Integration 8.5
Find case ids based on url input or "existing case" settings
1 call to WebformCivicrmPreProcess::findExistingCases()
- 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 659 - Front-end form pre-processor.
Class
Namespace
Drupal\webform_civicrmCode
private function findExistingCases() {
$utils = \Drupal::service('webform_civicrm.utils');
// Support legacy url param
if (empty($_GET["case1"]) && !empty($_GET["caseid"])) {
$_GET["case1"] = $_GET["caseid"];
}
for ($n = 1; $n <= $this->data['case']['number_of_case']; ++$n) {
if (!empty($this->data['case'][$n]['case'][1]['client_id'])) {
$clients = [];
foreach ((array) $this->data['case'][$n]['case'][1]['client_id'] as $c) {
if (!empty($this->ent['contact'][$c]['id'])) {
$clients[] = $this->ent['contact'][$c]['id'];
}
}
if ($clients) {
// Populate via url argument
if (isset($_GET["case{$n}"]) && $utils
->wf_crm_is_positive($_GET["case{$n}"])) {
$id = $_GET["case{$n}"];
$item = $utils
->wf_civicrm_api('case', 'getsingle', [
'id' => $id,
]);
if (array_intersect((array) wf_crm_aval($item, 'client_id'), $clients)) {
$this->ent['case'][$n] = [
'id' => $id,
];
}
}
elseif (!empty($this->data['case'][$n]['existing_case_status'])) {
$item = $this
->findCaseForContact($clients, [
'case_type_id' => wf_crm_aval($this->data['case'][$n], 'case:1:case_type_id'),
'status_id' => $this->data['case'][$n]['existing_case_status'],
]);
if ($item) {
$this->ent['case'][$n] = [
'id' => $item['id'],
];
}
}
}
}
}
}