Don't repeat crmButton block
authorlarssandergreen <lars@wildsight.ca>
Sat, 23 Sep 2023 04:27:04 +0000 (22:27 -0600)
committerlarssandergreen <lars@wildsight.ca>
Sat, 23 Sep 2023 04:27:21 +0000 (22:27 -0600)
CRM/Core/Smarty/plugins/block.crmButton.php

index 64543d5957683dbbf5d193dda100261bd8f42140..fbd6606329e72f8a11e8f8fc8bdbc8c86d480d8d 100644 (file)
  *   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 = "<i class='crm-i $icon' aria-hidden=\"true\"></i> ";
     }
-    $iconMarkup = "<i class='crm-i $icon' aria-hidden=\"true\"></i> ";
+    // 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 "<a $attributes><span>$iconMarkup$text</span></a>";
   }
-  // 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 "<a $attributes><span>$iconMarkup$text</span></a>";
 }