From 7abcf851652c4e5365a6b68556ec7e20bf8f5cde Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Tue, 6 Jun 2023 09:28:36 -0600 Subject: [PATCH] Get help text title from field label if htxt title is not provided --- CRM/Core/Form/Renderer.php | 1 + CRM/Core/Smarty/plugins/function.help.php | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index e606b25b8c..bda38ac894 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -85,6 +85,7 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { self::updateAttributes($element, $required, $error); $el = parent::_elementToArray($element, $required, $error); + $el['textLabel'] = $element->_label ?? NULL; // add label html if (!empty($el['label'])) { diff --git a/CRM/Core/Smarty/plugins/function.help.php b/CRM/Core/Smarty/plugins/function.help.php index 1a1a8ad8af..2a0a2804d9 100644 --- a/CRM/Core/Smarty/plugins/function.help.php +++ b/CRM/Core/Smarty/plugins/function.help.php @@ -39,22 +39,21 @@ function smarty_function_help($params, &$smarty) { } $params['file'] = str_replace(['.tpl', '.hlp'], '', $params['file']); + $fieldID = str_replace('-', '_', preg_replace('/^id-/', '', $params['id'])); if (empty($params['title'])) { $vars = $smarty->get_template_vars(); $smarty->assign('id', $params['id'] . '-title'); - $name = trim($smarty->fetch($params['file'] . '.hlp')); - $extraoutput = ''; + $name = trim($smarty->fetch($params['file'] . '.hlp')) ?: $vars['form'][$fieldID]['textLabel'] ?? ''; $additionalTPLFile = $params['file'] . '.extra.hlp'; if ($smarty->template_exists($additionalTPLFile)) { - $extraoutput .= trim($smarty->fetch($additionalTPLFile)); - // Allow override param to replace default text e.g. {hlp id='foo' override=1} - if ($smarty->get_template_vars('override_help_text')) { - $name = ''; + $extraoutput = trim($smarty->fetch($additionalTPLFile)); + if ($extraoutput) { + // Allow override param to replace default text e.g. {hlp id='foo' override=1} + $name = ($smarty->get_template_vars('override_help_text') || empty($name)) ? $extraoutput : $name . ' ' . $extraoutput; } } - $name .= $extraoutput; // Ensure we didn't change any existing vars CRM-11900 foreach ($vars as $key => $value) { @@ -64,7 +63,7 @@ function smarty_function_help($params, &$smarty) { } } else { - $name = trim(strip_tags($params['title'])); + $name = trim(strip_tags($params['title'])) ?: $vars['form'][$fieldID]['textLabel'] ?? ''; } $class = "helpicon"; -- 2.25.1