function webform_token_info_alter in Webform 6.x
Same name and namespace in other branches
- 8.5 webform.module \webform_token_info_alter()
Implements hook_token_info_alter().
File
- ./
webform.module, line 305 - Enables the creation of webforms and questionnaires.
Code
function webform_token_info_alter(&$data) {
module_load_include('inc', 'webform', 'webform.tokens.inc');
// Append learn more about token suffixes to all webform token descriptions.
// @see \Drupal\webform\WebformTokenManager::replace
// @see webform_page_attachments()
$token_suffixes = t('Append the below suffixes to alter the returned value.') . '<ul>' . '<li>' . t('<code>:clear</code> removes the token when it is not replaced.') . '</li>' . '<li>' . t('<code>:urlencode</code> URL encodes returned value.') . '</li>' . '<li>' . t('<code>:rawurlencode</code> Raw URL encodes returned value with only hex digits.') . '</li>' . '<li>' . t('<code>:xmlencode</code> XML encodes returned value.') . '</li>' . '<li>' . t('<code>:htmldecode</code> decodes HTML entities in returned value.') . '<br/><b>' . t('This suffix has security implications.') . '</b><br/>' . t('Use <code>:htmldecode</code> with <code>:striptags</code>.') . '</li>' . '<li>' . t('<code>:striptags</code> removes all HTML tags from returned value.') . '</li>' . '</ul>';
$more = _webform_token_render_more(t('Learn about token suffixes'), $token_suffixes);
foreach ($data['types'] as $type => &$info) {
if (strpos($type, 'webform') === 0) {
if (isset($info['description']) && !empty($info['description'])) {
$description = $info['description'] . $more;
}
else {
$description = $more;
}
$info['description'] = Markup::create($description);
}
}
}