function _webform_preprocess_description_help in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.theme.inc \_webform_preprocess_description_help()
Prepares #description and #help properties for form element templates.
1 call to _webform_preprocess_description_help()
- _webform_preprocess_element in includes/
webform.theme.inc - Prepares webform element description, help, and more templates.
File
- includes/
webform.theme.inc, line 818 - Theme hooks, preprocessor, and suggestions.
Code
function _webform_preprocess_description_help(array &$variables) {
$element =& $variables['element'];
// Move #description to #help for webform admin routes.
if (\Drupal::config('webform.settings')
->get('ui.description_help') && \Drupal::service('webform.request')
->isWebformAdminRoute() && \Drupal::routeMatch()
->getRouteName() !== 'webform.contribute.settings' && !isset($element['#help']) && !empty($element['#title']) && (empty($element['#title_display']) || !in_array($element['#title_display'], [
'attribute',
'invisible',
])) && !empty($element['#description']) && (empty($element['#description_display']) || !in_array($element['#description_display'], [
'invisible',
]))) {
// Render the description.
$description = is_array($element['#description']) ? \Drupal::service('renderer')
->render($element['#description']) : $element['#description'];
// Replace breaks in admin tooltips with horizontal rules.
$description = str_replace('<br /><br />', '<hr />', $description);
$element['#help'] = [
'#markup' => $description,
];
// We must still render the description as visually hidden because the input
// has an 'aria-describedby' attribute pointing to the description's id.
$variables['description_display'] = 'after';
$variables['description']['content']['description']['#attributes']
->addClass('visually-hidden');
// Remove all links from the #description since it will be .visually-hidden
// and unreachable via tabbing.
if (isset($variables['description']['content']['description']['#markup'])) {
$variables['description']['content']['description']['#markup'] = strip_tags($variables['description']['content']['description']['#markup']);
}
}
}