You are here

function wf_crm_replace_tokens in Webform CiviCRM Integration 7.3

Token replacement for form messages

Parameters

$str: Raw message with tokens

$contact: CiviCRM contact array

Return value

mixed

2 calls to wf_crm_replace_tokens()
_wf_crm_frontend_form_alter in ./webform_civicrm_forms.inc
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.
_wf_crm_set_message in ./webform_civicrm_forms.inc
Displays the admin-defined message with "not you?" link to known contacts

File

./webform_civicrm_utils.inc, line 1257
Webform CiviCRM module's common utility functions.

Code

function wf_crm_replace_tokens($str, $contact) {
  $sp = CRM_Core_DAO::VALUE_SEPARATOR;
  $tokens = wf_crm_get_fields('tokens');
  $values = array();
  foreach ($tokens as $k => &$t) {
    if (empty($contact[$k])) {
      $contact[$k] = '';
    }
    $value = $contact[$k];
    if (is_array($value)) {
      $value = implode(', ', $value);
    }
    $values[] = str_replace($sp, ' & ', trim($value, $sp));
    $t = "[{$t}]";
  }
  return str_ireplace($tokens, $values, $str);
}