You are here

function webform_replace_tokens in Webform 7.4

Replace tokens with Webform contexts populated.

Parameters

$string: The string to have its tokens replaced.

object $node: If replacing node-level tokens, the node for which tokens will be created.

$submission: If replacing submission-level tokens, the submission for which tokens will be created.

$email: If replacing tokens within the context of an e-mail, the Webform e-mail settings array.

$sanitize: Boolean or format name value indicating if the results will be displayed as HTML output. If FALSE, the contents returned will be unsanitized. This will also result in all Webform submission tokens being returned as plain-text, without HTML markup, in preparation for e-mailing or other text-only purposes (default values, etc.). If TRUE, the tokens only are sanitized by token_replace. Otherwise $sanitize is the machine name of an import filter to be used with check_markup().

27 calls to webform_replace_tokens()
template_preprocess_webform_confirmation in ./webform.module
Prepare for theming of the webform submission confirmation.
webform_block_view in ./webform.module
Implements hook_block_view().
webform_client_form in ./webform.module
Client form generation function.
webform_client_form_submit in ./webform.module
Submit handler for saving the form values and sending e-mails.
webform_configure_form_validate in includes/webform.pages.inc
Validate handler for webform_configure_form().

... See full list

File

./webform.module, line 4079
This module provides a simple way to create forms and questionnaires.

Code

function webform_replace_tokens($string, $node = NULL, $submission = NULL, $email = NULL, $sanitize = FALSE) {

  // Don't do any filtering if the string is empty.
  if (!strlen(trim($string)) || !webform_variable_get('webform_token_access')) {
    return $string;
  }
  $token_data = array();
  if ($node) {
    $token_data['node'] = $node;
  }
  if ($submission) {
    $token_data['webform-submission'] = $submission;
  }
  if ($email) {
    $token_data['webform-email'] = $email;
  }
  $clear = is_bool($sanitize);
  $string = token_replace($string, $token_data, array(
    'clear' => $clear,
    'sanitize' => $sanitize === TRUE,
  ));
  if (!$clear) {
    $string = webform_replace_tokens_clear(check_markup($string, $sanitize));
  }
  return $string;
}