You are here

function _webform_civicrm_replaceActivityLinkTokens in Webform CiviCRM Integration 8.5

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

Replaces activity-link tokens with civicrm activity page links

Parameters

array $tokens: Tokens to process

array $webformSubmissionData: Data submitted by the webform

Return value

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

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

File

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

Code

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