You are here

private function WebformCivicrmPostProcess::fillHiddenContactFields in Webform CiviCRM Integration 8.5

Fill values for hidden ID & CS fields

id

Parameters

int $c:

1 call to WebformCivicrmPostProcess::fillHiddenContactFields()
WebformCivicrmPostProcess::preSave in src/WebformCivicrmPostProcess.php
Process webform submission when it is about to be saved. Called by the following hook:

File

src/WebformCivicrmPostProcess.php, line 784
Front-end form validation and post-processing.

Class

WebformCivicrmPostProcess

Namespace

Drupal\webform_civicrm

Code

private function fillHiddenContactFields($cid, $c) {
  $utils = \Drupal::service('webform_civicrm.utils');
  $fid = 'civicrm_' . $c . '_contact_1_contact_';
  if (!empty($this->enabled[$fid . 'contact_id'])) {
    $this
      ->submissionValue($this->enabled[$fid . 'contact_id'], $cid);
  }
  if (!empty($this->enabled[$fid . 'user_id'])) {
    $user_id = $utils
      ->wf_crm_user_cid($cid, 'contact');
    $user_id = $user_id ? $user_id : '';
    $this
      ->submissionValue($this->enabled[$fid . 'user_id'], $user_id);
  }
  if (!empty($this->enabled[$fid . 'existing'])) {
    $this
      ->submissionValue($this->enabled[$fid . 'existing'], $cid);
  }
  if (!empty($this->enabled[$fid . 'external_identifier']) && !empty($this->existing_contacts[$c])) {
    $exid = $utils
      ->wf_civicrm_api('contact', 'get', [
      'contact_id' => $cid,
      'return.external_identifier' => 1,
    ]);
    $this
      ->submissionValue($this->enabled[$fid . 'external_identifier'], wf_crm_aval($exid, "values:{$cid}:external_identifier"));
  }
  if (!empty($this->enabled[$fid . 'cs'])) {
    $cs = $this
      ->submissionValue($this->enabled[$fid . 'cs']);
    $life = !empty($cs[0]) ? intval(24 * $cs[0]) : 'inf';
    $cs = \CRM_Contact_BAO_Contact_Utils::generateChecksum($cid, NULL, $life);
    $this
      ->submissionValue($this->enabled[$fid . 'cs'], $cs);
  }
}