function social_event_render_tooltip in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/social_features/social_event/social_event.module \social_event_render_tooltip()
- 10.1.x modules/social_features/social_event/social_event.module \social_event_render_tooltip()
- 10.2.x modules/social_features/social_event/social_event.module \social_event_render_tooltip()
Returns a new popover tooltip based on a descriptive text and field name.
Parameters
string $field_name: The field name to create a unique id for.
string $data_title: The title of the pop-up.
string $description: A string containing the description, this needs to be rendered markup.
Return value
array The render array containing the tooltip.
1 call to social_event_render_tooltip()
- social_event_preprocess_fieldset in modules/
social_features/ social_event/ social_event.module - Implements template_preprocess_form_element().
File
- modules/
social_features/ social_event/ social_event.module, line 1176 - The Social event module.
Code
function social_event_render_tooltip($field_name, $data_title, $description) {
$build = [];
$id = Html::getUniqueId('tooltip-' . $field_name);
$build['toggle'] = [
'#type' => 'link',
'#url' => Url::fromUserInput("#{$id}"),
'#icon' => Bootstrap::glyphicon('question-sign'),
'#attributes' => [
'class' => [
'icon-before',
],
'data-toggle' => 'popover',
'data-container' => 'body',
'data-html' => 'true',
'data-placement' => 'bottom',
'data-title' => $data_title ?: '',
],
];
$build['requirements'] = [
'#type' => 'container',
'#theme_wrappers' => [
'container__file_upload_help',
],
'#attributes' => [
'id' => $id,
'class' => [
'hidden',
'help-block',
],
'aria-hidden' => 'true',
],
];
// As documented in Render API, Note that the value is passed through
// \Drupal\Component\Utility\Xss::filterAdmin(), which strips known XSS
// vectors while allowing a permissive list of HTML tags.
$build['requirements']['descriptions'] = [
'#markup' => $description,
'#allowed_tags' => [
'strong',
'span',
'svg',
'p',
'div',
'em',
'img',
'a',
'span',
'use',
],
];
$variables['popover'] = $build;
return $build;
}