You are here

function _webform_civicrm_replaceCaseLinkTokens in Webform CiviCRM Integration 8.5

Same name and namespace in other branches
  1. 7.5 webform_civicrm.module \_webform_civicrm_replaceCaseLinkTokens()
  2. 7.4 webform_civicrm.module \_webform_civicrm_replaceCaseLinkTokens()

Replaces case-link tokens with civicrm case page links

Parameters

array $tokens: Tokens to process

array $webformSubmissionData: Data submitted by the webform

Return value

array List of replaced case-link tokens replaced with actual case links

1 call to _webform_civicrm_replaceCaseLinkTokens()
webform_civicrm_tokens in ./webform_civicrm.module
Implements hook_tokens().

File

./webform_civicrm.module, line 859
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function _webform_civicrm_replaceCaseLinkTokens($tokens, $webformSubmissionData) {
  $replacedTokens = [];
  $tokenValues = \Drupal::token()
    ->findWithPrefix($tokens, 'case-link');
  if (!$tokenValues) {
    return $replacedTokens;
  }
  foreach ($tokenValues as $entityID => $tokenName) {
    $tokenNewValue = '';
    if (!empty($webformSubmissionData['civicrm']['case'][$entityID]['id'])) {
      $caseID = $webformSubmissionData['civicrm']['case'][$entityID]['id'];
      $caseContactID = _webform_civicrm_getCaseContactID($caseID);
      $tokenNewValue = Url::fromUri('internal:/civicrm/contact/view/case', [
        'absolute' => TRUE,
        'query' => [
          'reset' => 1,
          'id' => $caseID,
          'cid' => $caseContactID,
          'action' => 'view',
        ],
      ])
        ->toString();
    }
    $replacedTokens[$tokenName] = $tokenNewValue;
  }
  return $replacedTokens;
}