From 256a04058b62c9f4c8204ba18f8b9bdebec6e05f Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Sun, 24 Sep 2023 13:26:25 -0600 Subject: [PATCH] Don't repeat Smarty blocks --- .../plugins/block.crmUpgradeSnapshot.php | 6 +++-- CRM/Core/Smarty/plugins/block.edit.php | 12 ++++++---- CRM/Core/Smarty/plugins/block.htxt.php | 8 ++++--- CRM/Core/Smarty/plugins/block.icon.php | 23 +++++++++++-------- CRM/Core/Smarty/plugins/block.ts.php | 14 +++++++---- CRM/Core/Smarty/plugins/block.url.php | 7 ++++-- 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/CRM/Core/Smarty/plugins/block.crmUpgradeSnapshot.php b/CRM/Core/Smarty/plugins/block.crmUpgradeSnapshot.php index 9e95233751..44571c14ed 100644 --- a/CRM/Core/Smarty/plugins/block.crmUpgradeSnapshot.php +++ b/CRM/Core/Smarty/plugins/block.crmUpgradeSnapshot.php @@ -32,11 +32,13 @@ * @param string|null $text * The SELECT query which supplies the interesting data to be stored in the snapshot. * @param CRM_Core_Smarty $smarty + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag * @return string|null * @throws \CRM_Core_Exception */ -function smarty_block_crmUpgradeSnapshot($params, $text, &$smarty) { - if ($text === NULL) { +function smarty_block_crmUpgradeSnapshot($params, $text, &$smarty, &$repeat) { + if ($repeat || $text === NULL) { return NULL; } diff --git a/CRM/Core/Smarty/plugins/block.edit.php b/CRM/Core/Smarty/plugins/block.edit.php index d42fe44e03..cb3d15479d 100644 --- a/CRM/Core/Smarty/plugins/block.edit.php +++ b/CRM/Core/Smarty/plugins/block.edit.php @@ -30,11 +30,15 @@ * {edit} block contents from the template. * @param CRM_Core_Smarty $smarty * The Smarty object. + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag * - * @return string + * @return string|null * the string, translated by gettext */ -function smarty_block_edit($params, $text, &$smarty) { - $action = $smarty->_tpl_vars['action']; - return ($action & 3) ? $text : NULL; +function smarty_block_edit($params, $text, &$smarty, &$repeat) { + if (!$repeat) { + $action = $smarty->get_template_vars()['action']; + return ($action & 3) ? $text : NULL; + } } diff --git a/CRM/Core/Smarty/plugins/block.htxt.php b/CRM/Core/Smarty/plugins/block.htxt.php index cfd03732c1..b206cb616c 100644 --- a/CRM/Core/Smarty/plugins/block.htxt.php +++ b/CRM/Core/Smarty/plugins/block.htxt.php @@ -26,12 +26,14 @@ * {ts} block contents from the template. * @param CRM_Core_Smarty $smarty * The Smarty object. + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag * - * @return string + * @return string|null * the string, translated by gettext */ -function smarty_block_htxt($params, $text, &$smarty) { - if ($params['id'] == $smarty->_tpl_vars['id']) { +function smarty_block_htxt($params, $text, &$smarty, &$repeat) { + if (!$repeat && $params['id'] == $smarty->_tpl_vars['id']) { $smarty->assign('override_help_text', !empty($params['override'])); return $text; } diff --git a/CRM/Core/Smarty/plugins/block.icon.php b/CRM/Core/Smarty/plugins/block.icon.php index 97dbb6d55d..84865c63d4 100644 --- a/CRM/Core/Smarty/plugins/block.icon.php +++ b/CRM/Core/Smarty/plugins/block.icon.php @@ -30,14 +30,19 @@ * * @param $smarty * - * @return string + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag + * + * @return string|null */ -function smarty_block_icon($params, $text, &$smarty) { - $condition = array_key_exists('condition', $params) ? $params['condition'] : 1; - $icon = $params['icon'] ?? 'fa-check'; - $dontPass = [ - 'condition' => 1, - 'icon' => 1, - ]; - return CRM_Core_Page::crmIcon($icon, $text, $condition, array_diff_key($params, $dontPass)); +function smarty_block_icon($params, $text, &$smarty, &$repeat) { + if (!$repeat) { + $condition = array_key_exists('condition', $params) ? $params['condition'] : 1; + $icon = $params['icon'] ?? 'fa-check'; + $dontPass = [ + 'condition' => 1, + 'icon' => 1, + ]; + return CRM_Core_Page::crmIcon($icon, $text, $condition, array_diff_key($params, $dontPass)); + } } diff --git a/CRM/Core/Smarty/plugins/block.ts.php b/CRM/Core/Smarty/plugins/block.ts.php index 785122d36e..cb077675de 100644 --- a/CRM/Core/Smarty/plugins/block.ts.php +++ b/CRM/Core/Smarty/plugins/block.ts.php @@ -29,13 +29,17 @@ * {ts} block contents from the template. * @param CRM_Core_Smarty $smarty * The Smarty object. + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag * - * @return string + * @return string|null * the string, translated by gettext */ -function smarty_block_ts($params, $text, &$smarty) { - if (!isset($params['domain']) && $extensionKey = $smarty->get_template_vars('extensionKey')) { - $params['domain'] = is_array($extensionKey) ? $extensionKey : [$extensionKey, NULL]; +function smarty_block_ts($params, $text, &$smarty, &$repeat) { + if (!$repeat) { + if (!isset($params['domain']) && $extensionKey = $smarty->get_template_vars('extensionKey')) { + $params['domain'] = is_array($extensionKey) ? $extensionKey : [$extensionKey, NULL]; + } + return _ts($text, $params); } - return _ts($text, $params); } diff --git a/CRM/Core/Smarty/plugins/block.url.php b/CRM/Core/Smarty/plugins/block.url.php index 71814af2a1..890d9d20b4 100644 --- a/CRM/Core/Smarty/plugins/block.url.php +++ b/CRM/Core/Smarty/plugins/block.url.php @@ -34,10 +34,13 @@ * Contents of block. * @param CRM_Core_Smarty $smarty * The Smarty object. + * @param bool $repeat + * Repeat is true for the opening tag, false for the closing tag + * * @return string */ -function smarty_block_url($params, $text, &$smarty) { - if ($text === NULL) { +function smarty_block_url($params, $text, &$smarty, &$repeat) { + if ($repeat || $text === NULL) { return NULL; } -- 2.25.1