function template_preprocess_webform_element_help in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.theme.template.inc \template_preprocess_webform_element_help()
Prepares variables for webform element help templates.
Default template: webform-element-help.html.twig.
Parameters
array $variables: An associative array containing the following key:
- element: The webform element.
- help: The help content.
- attributes: The help attributes.
File
- includes/
webform.theme.template.inc, line 873 - Preprocessors and helper functions to make theming easier.
Code
function template_preprocess_webform_element_help(array &$variables) {
$attributes = isset($variables['attributes']) ? $variables['attributes'] : [];
$attributes['class'][] = 'webform-element-help';
$attributes['class'][] = 'js-webform-element-help';
$attributes['role'] = 'tooltip';
$attributes['tabindex'] = '0';
$attributes['aria-label'] = $variables['help_title'] ?: t('Help tooltip');
$content = is_array($variables['help']) ? \Drupal::service('renderer')
->render($variables['help']) : $variables['help'];
$help = '';
if (!empty($variables['help_title'])) {
$help .= '<div class="webform-element-help--title">' . WebformHtmlEditor::stripTags($variables['help_title']) . '</div>';
}
$help .= '<div class="webform-element-help--content">' . WebformHtmlEditor::stripTags($content) . '</div>';
$attributes['data-webform-help'] = $help;
$variables['attributes'] = new Attribute($attributes);
}