Merge pull request #21945 from masetto/profile-data-attribute
[civicrm-core.git] / CRM / Core / Smarty / plugins / function.help.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * Adds inline help
20 *
6a0b768e
TO
21 * @param array $params
22 * The function params.
16b10e64 23 * @param CRM_Core_Smarty $smarty
6a0b768e 24 * Reference to the smarty object.
6a488035 25 *
a6c01b45 26 * @return string
353ffa53 27 * the help html to be inserted
6a488035
TO
28 */
29function smarty_function_help($params, &$smarty) {
30 if (!isset($params['id']) || !isset($smarty->_tpl_vars['config'])) {
a1a2a83d 31 return NULL;
6a488035
TO
32 }
33
6a488035
TO
34 if (empty($params['file']) && isset($smarty->_tpl_vars['tplFile'])) {
35 $params['file'] = $smarty->_tpl_vars['tplFile'];
36 }
37 elseif (empty($params['file'])) {
6eea17da 38 return NULL;
6a488035
TO
39 }
40
be2fb01f 41 $params['file'] = str_replace(['.tpl', '.hlp'], '', $params['file']);
6a488035
TO
42
43 if (empty($params['title'])) {
6441e8d7 44 $vars = $smarty->get_template_vars();
6a488035 45 $smarty->assign('id', $params['id'] . '-title');
9bb40657 46
6a488035 47 $name = trim($smarty->fetch($params['file'] . '.hlp'));
9bb40657 48 $extraoutput = '';
6eea17da
E
49 $additionalTPLFile = $params['file'] . '.extra.hlp';
50 if ($smarty->template_exists($additionalTPLFile)) {
9bb40657
BS
51 $extraoutput .= trim($smarty->fetch($additionalTPLFile));
52 // Allow override param to replace default text e.g. {hlp id='foo' override=1}
53 if ($smarty->get_template_vars('override_help_text')) {
54 $name = '';
55 }
6eea17da 56 }
9bb40657
BS
57 $name .= $extraoutput;
58
6441e8d7
CW
59 // Ensure we didn't change any existing vars CRM-11900
60 foreach ($vars as $key => $value) {
61 if ($smarty->get_template_vars($key) !== $value) {
62 $smarty->assign($key, $value);
63 }
64 }
6a488035
TO
65 }
66 else {
67 $name = trim(strip_tags($params['title']));
68 }
6eea17da 69
1bf65b67 70 $class = "helpicon";
71 if (!empty($params['class'])) {
72 $class .= " {$params['class']}";
73 }
74
4bc223d1 75 // Escape for html
be2fb01f 76 $title = htmlspecialchars(ts('%1 Help', [1 => $name]));
4bc223d1
CW
77 // Escape for html and js
78 $name = htmlspecialchars(json_encode($name), ENT_QUOTES);
79
6a488035 80 // Format params to survive being passed through json & the url
4bc223d1 81 unset($params['text'], $params['title']);
6a488035
TO
82 foreach ($params as &$param) {
83 $param = is_bool($param) || is_numeric($param) ? (int) $param : (string) $param;
84 }
c7915cc9 85 return '<a class="' . $class . '" title="' . $title . '" aria-label="' . $title . '" href="#" onclick=\'CRM.help(' . $name . ', ' . json_encode($params) . '); return false;\'>&nbsp;</a>';
6a488035 86}