private function WebformCivicrmPreProcess::populateExistingEntity in Webform CiviCRM Integration 8.5
Populate existing entity data
Parameters
string $type entity type (activity, case, grant):
1 call to WebformCivicrmPreProcess::populateExistingEntity()
- 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 794 - Front-end form pre-processor.
Class
Namespace
Drupal\webform_civicrmCode
private function populateExistingEntity($type) {
$items = [];
$utils = \Drupal::service('webform_civicrm.utils');
foreach ($this->ent[$type] as $key => $item) {
if (!empty($item['id'])) {
$items[$key] = $item['id'];
}
}
if ($items) {
$values = $utils
->wf_crm_apivalues($type, 'get', [
'id' => [
'IN' => array_values($items),
],
]);
foreach ($items as $n => $id) {
if (isset($values[$id])) {
// Load core + custom data
$this->info[$type][$n] = [
$type => [
1 => $values[$id],
],
] + $this
->getCustomData($id, $type);
// Load file attachments
if (!empty($this->all_sets["{$type}upload"])) {
foreach ($this
->getAttachments($type, $id) as $f => $file) {
$this->info[$type][$n]["{$type}upload"][1]["file_{$f}"] = $file['file_id'];
}
}
// Load tags
$tags = NULL;
foreach (array_keys($this->enabled) as $fid) {
if (strpos($fid, "civicrm_{$n}_{$type}_1_{$type}_tag") === 0) {
$tags = $tags ?? $utils
->wf_crm_apivalues('EntityTag', 'get', [
'entity_id' => $id,
'entity_table' => "civicrm_" . $type,
'sequential' => 1,
], 'tag_id');
$this->info[$type][$n][$type][1][str_replace("civicrm_{$n}_{$type}_1_{$type}_", '', $fid)] = $tags;
}
}
}
}
}
}