You are here

function webform_civicrm_replace_tokens in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_utils.inc \webform_civicrm_replace_tokens()
  2. 6 webform_civicrm_utils.inc \webform_civicrm_replace_tokens()
  3. 7 webform_civicrm_utils.inc \webform_civicrm_replace_tokens()

Token replacement for form messages

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

File

./webform_civicrm_utils.inc, line 952
Webform CiviCRM module's common utility functions. The code in this file is cross-compatible with D6/Civi3 and D7/Civi4 Drupal-version-specific functions belong in webform_civicrm_dx_functions.inc

Code

function webform_civicrm_replace_tokens($str, $contact) {
  $sp = CRM_Core_DAO::VALUE_SEPARATOR;
  $tokens = webform_civicrm_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);
}