private function WebformCivicrmPreProcess::replaceTokens in Webform CiviCRM Integration 8.5
Token replacement for form messages
Parameters
$str: Raw message with tokens
$contact: CiviCRM contact array
Return value
mixed
2 calls to WebformCivicrmPreProcess::replaceTokens()
- WebformCivicrmPreProcess::alterForm in src/
WebformCivicrmPreProcess.php - 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.
- WebformCivicrmPreProcess::showNotYouMessage in src/
WebformCivicrmPreProcess.php - Displays the admin-defined message with "not you?" link to known contacts
File
- src/
WebformCivicrmPreProcess.php, line 876 - Front-end form pre-processor.
Class
Namespace
Drupal\webform_civicrmCode
private function replaceTokens($str, $contact) {
$utils = \Drupal::service('webform_civicrm.utils');
$tokens = $utils
->wf_crm_get_fields('tokens');
$values = [];
foreach ($tokens as $k => &$t) {
if (empty($contact[$k])) {
$contact[$k] = '';
}
$value = $contact[$k];
if (is_array($value)) {
$value = implode(', ', $value);
}
$values[] = implode(' & ', $utils
->wf_crm_explode_multivalue_str($value));
$t = "[{$t}]";
}
return str_ireplace($tokens, $values, $str);
}