dev/core#1899 specify display mode for action links with icons
authorAndrew Hunt <andrew@aghstrategies.com>
Fri, 24 Jul 2020 00:46:27 +0000 (20:46 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Fri, 24 Jul 2020 22:39:26 +0000 (18:39 -0400)
CRM/Contribute/BAO/Contribution.php
CRM/Core/Action.php

index 10501932192fd8a196c2cbcd2a3fcae5fa5ab200..c209e67fcd2d08009d202e0aea31490d66e29636 100644 (file)
@@ -1311,7 +1311,8 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
           FALSE,
           'Payment.edit.action',
           'Payment',
-          $resultDAO->id
+          $resultDAO->id,
+          'icon'
         );
       }
 
index f1475076020c2c74c22a86799107120ccb391a78..2211d6cdb6eedc9c105a0c01e8fa0ceb4bf6e8c9 100644 (file)
@@ -178,6 +178,12 @@ class CRM_Core_Action {
    * @param null $op
    * @param null $objectName
    * @param int $objectId
+   * @param string $iconMode
+   *   - `text`: even if `icon` is set for a link, display the `name`
+   *   - `icon`: display only the `icon` for each link if it's available, and
+   *     don't tuck anything under "more >"
+   *   - `both`: if `icon` is available, display it next to the `name` for each
+   *     link
    *
    * @return string
    *   the html string
@@ -190,7 +196,8 @@ class CRM_Core_Action {
     $enclosedAllInSingleUL = FALSE,
     $op = NULL,
     $objectName = NULL,
-    $objectId = NULL
+    $objectId = NULL,
+    $iconMode = 'text'
   ) {
     if (empty($links)) {
       return NULL;
@@ -243,11 +250,22 @@ class CRM_Core_Action {
         if (strpos($urlPath, '/delete') || strpos($urlPath, 'action=delete')) {
           $classes .= " small-popup";
         }
+
+        $linkContent = $link['name'];
+        if (!empty($link['icon'])) {
+          if ($iconMode == 'icon') {
+            $linkContent = CRM_Core_Page::crmIcon($link['icon'], $link['name'], TRUE, ['title' => '']);
+          }
+          elseif ($iconMode == 'both') {
+            $linkContent = CRM_Core_Page::crmIcon($link['icon']) . ' ' . $linkContent;
+          }
+        }
+
         $url[] = sprintf('<a href="%s" class="%s" %s' . $extra . '>%s</a>',
           $urlPath,
           $classes,
           !empty($link['title']) ? "title='{$link['title']}' " : '',
-          empty($link['icon']) ? $link['name'] : CRM_Core_Page::crmIcon($link['icon'], $link['name'], TRUE, ['title' => ''])
+          $linkContent
         );
       }
     }
@@ -261,11 +279,13 @@ class CRM_Core_Action {
     }
     else {
       $extra = '';
-      $extraLinks = array_splice($url, 2);
-      if (count($extraLinks) > 1) {
-        $mainLinks = array_slice($url, 0, 2);
-        CRM_Utils_String::append($extra, '</li><li>', $extraLinks);
-        $extra = "{$extraULName}<ul class='panel'><li>{$extra}</li></ul>";
+      if ($iconMode != 'icon') {
+        $extraLinks = array_splice($url, 2);
+        if (count($extraLinks) > 1) {
+          $mainLinks = array_slice($url, 0, 2);
+          CRM_Utils_String::append($extra, '</li><li>', $extraLinks);
+          $extra = "{$extraULName}<ul class='panel'><li>{$extra}</li></ul>";
+        }
       }
       $resultLinks = '';
       CRM_Utils_String::append($resultLinks, '', $mainLinks);