You are here

function webform_replace_tokens_clear in Webform 7.4

Removes tokens from string.

Call this function in cases where you need to remove unreplaced tokens but can't call webform_replace_tokens() with the option $clear = TRUE.

In some cases the function token_replace() in webform_replace_tokens() needs to be called with the option 'clear' => FALSE, to not remove input filters. For security reasons webform_replace_tokens() is called before check_markup(), where input filters get replaced. Tokens won't be replaced if there is no value provided. These tokens, that is, [current-page:query:*] needs to be removed to not show up in the output.

Note: This function was previously named webform_clear_tokens, which conflicted with the webform_clear module, being called as hook_tokens.

Parameters

string $text: The text to have its tokens removed.

Return value

mixed|string Replace tokens with actual value.

See also

token_replace()

1 call to webform_replace_tokens_clear()
webform_replace_tokens in ./webform.module
Replace tokens with Webform contexts populated.

File

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

Code

function webform_replace_tokens_clear($text) {
  if (empty($text) || !webform_variable_get('webform_token_access')) {
    return $text;
  }
  $text_tokens = token_scan($text);
  if (empty($text_tokens)) {
    return $text;
  }
  $replacements = array();
  foreach ($text_tokens as $type => $tokens) {
    $replacements += array_fill_keys($tokens, '');
  }
  $tokens = array_keys($replacements);
  $values = array_values($replacements);
  return str_replace($tokens, $values, $text);
}