function social_group_render_tooltip in Open Social 10.2.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_group/social_group.module \social_group_render_tooltip()
- 10.0.x modules/social_features/social_group/social_group.module \social_group_render_tooltip()
- 10.1.x modules/social_features/social_group/social_group.module \social_group_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.
\Drupal\Core\StringTranslation\TranslatableMarkup $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.
3 calls to social_group_render_tooltip()
- social_group_flexible_group_preprocess_fieldset in modules/
social_features/ social_group/ modules/ social_group_flexible_group/ social_group_flexible_group.module - Implements template_preprocess_form_element().
- social_group_preprocess_fieldset in modules/
social_features/ social_group/ social_group.module - Implements template_preprocess_form_element().
- _social_group_render_group_settings_hero in modules/
social_features/ social_group/ social_group.module - Renders the group settings based on available fields for the hero.
File
- modules/
social_features/ social_group/ social_group.module, line 2533 - The Social group module.
Code
function social_group_render_tooltip($field_name, TranslatableMarkup $data_title, $description) {
$build = [];
$id = Html::getUniqueId('tooltip-' . $field_name);
$icon = Bootstrap::glyphicon('question-sign');
$title = '';
// We special case this for the hero.
if ($field_name === 'group_hero') {
$data_title = t('Access permissions');
// For SKY we can render a bigger icon.
$icon_size = 'icon-small';
if (theme_get_setting('style') === 'sky') {
$icon_size = 'icon-medium';
$title = t('Access permissions');
}
$icon = [
'#type' => "inline_template",
'#template' => '<svg class="icon-white ' . $icon_size . '"><use xlink:href="#icon-cog"></use></svg>',
];
}
$build['toggle'] = [
'#type' => 'link',
'#url' => Url::fromUserInput("#{$id}"),
'#icon' => $icon,
'#title' => $title,
'#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;
}