From 00b7bae91826a67e22e384b1df791288234e2cb9 Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Fri, 22 Sep 2023 22:27:04 -0600 Subject: [PATCH] Don't repeat crmButton block --- CRM/Core/Smarty/plugins/block.crmButton.php | 52 +++++++++++---------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/CRM/Core/Smarty/plugins/block.crmButton.php b/CRM/Core/Smarty/plugins/block.crmButton.php index 64543d5957..fbd6606329 100644 --- a/CRM/Core/Smarty/plugins/block.crmButton.php +++ b/CRM/Core/Smarty/plugins/block.crmButton.php @@ -24,33 +24,37 @@ * 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 + * @return string|null * The generated html. */ -function smarty_block_crmButton($params, $text, &$smarty) { - // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes) - if (empty($params['href'])) { - $params['href'] = CRM_Utils_System::crmURL($params + ['h' => FALSE]); - } - // Always add class 'button' - fixme probably should be crm-button - $params['class'] = empty($params['class']) ? 'button' : 'button ' . $params['class']; - // Any FA icon works - if (array_key_exists('icon', $params) && !$params['icon']) { - // icon=0 should produce a button with no icon - $iconMarkup = ''; - } - else { - $icon = $params['icon'] ?? 'fa-pencil'; - // Assume for now that all icons are Font Awesome v4.x but handle if it's - // specified - if (strpos($icon, 'fa-') !== 0) { - $icon = "fa-$icon"; +function smarty_block_crmButton($params, $text, &$smarty, &$repeat) { + if (!$repeat) { + // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes) + if (empty($params['href'])) { + $params['href'] = CRM_Utils_System::crmURL($params + ['h' => FALSE]); + } + // Always add class 'button' - fixme probably should be crm-button + $params['class'] = empty($params['class']) ? 'button' : 'button ' . $params['class']; + // Any FA icon works + if (array_key_exists('icon', $params) && !$params['icon']) { + // icon=0 should produce a button with no icon + $iconMarkup = ''; + } + else { + $icon = $params['icon'] ?? 'fa-pencil'; + // Assume for now that all icons are Font Awesome v4.x but handle if it's + // specified + if (strpos($icon, 'fa-') !== 0) { + $icon = "fa-$icon"; + } + $iconMarkup = " "; } - $iconMarkup = " "; + // All other params are treated as html attributes + CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe'); + $attributes = CRM_Utils_String::htmlAttributes($params); + return "$iconMarkup$text"; } - // All other params are treated as html attributes - CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe'); - $attributes = CRM_Utils_String::htmlAttributes($params); - return "$iconMarkup$text"; } -- 2.25.1