SearchKit - Make contribution tasks available as actions
authorColeman Watts <coleman@civicrm.org>
Thu, 8 Apr 2021 19:03:38 +0000 (15:03 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 8 Apr 2021 20:47:43 +0000 (16:47 -0400)
So far there is only one action (Send Receipt) available,
and it only works for contributions with status=Completed.
SearchKit doesn't yet respect that limitation and shows the action for every record.

CRM/Contribute/Task.php
ext/search/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php

index 01dad553a9e9a8f572fe9f193416b6b6f686d1c8..ffe0cab0c39af5457253bf55a6e48109054a57c3 100644 (file)
@@ -91,8 +91,9 @@ class CRM_Contribute_Task extends CRM_Core_Task {
           'result' => FALSE,
           'title_single_mode' => ts('Send Receipt'),
           'name' => ts('Send Receipt'),
-          'is_support_standalone' => TRUE,
+          'url' => 'civicrm/contribute/task?reset=1&task=receipt',
           'key' => 'receipt',
+          'icon' => 'fa-envelope-o',
           'filters' => ['contribution_status_id' => [CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')]],
           'is_single_mode' => TRUE,
         ],
@@ -151,8 +152,8 @@ class CRM_Contribute_Task extends CRM_Core_Task {
           }
         }
       }
-      $tasks[$key]['url'] = 'civicrm/contribute/task';
-      $tasks[$key]['qs'] = ['reset' => 1, 'id' => $row['contribution_id'], 'task' => $task['key']];
+      $tasks[$key]['url'] = $task['url'];
+      $tasks[$key]['qs'] = ['id' => $row['contribution_id']];
       $tasks[$key]['title'] = $task['title_single_mode'] ?? $task['title'];
     }
     return $tasks;
index 4cd63717def6c14d0243e4a71a271bfeb81ee440..ff34da0f2d6f19f161a525db23635fbc56a56e96 100644 (file)
@@ -41,7 +41,7 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
         'icon' => 'fa-file-excel-o',
         'crmPopup' => [
           'path' => "'civicrm/export/standalone'",
-          'query' => "{entity: '{$entity['name']}', id: ids.join(',')}",
+          'query' => "{reset: 1, entity: '{$entity['name']}', id: ids.join(',')}",
         ],
       ];
     }
@@ -78,7 +78,23 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
             'icon' => $task['icon'] ?? 'fa-gear',
             'crmPopup' => [
               'path' => "'{$task['url']}'",
-              'query' => "{cids: ids.join(',')}",
+              'query' => "{reset: 1, cids: ids.join(',')}",
+            ],
+          ];
+        }
+      }
+    }
+
+    if ($entity['name'] === 'Contribution') {
+      foreach (\CRM_Contribute_Task::tasks() as $id => $task) {
+        if (!empty($task['url'])) {
+          $tasks[] = [
+            'name' => 'contribution.' . $id,
+            'title' => $task['title'],
+            'icon' => $task['icon'] ?? 'fa-gear',
+            'crmPopup' => [
+              'path' => "'{$task['url']}'",
+              'query' => "{id: ids.join(',')}",
             ],
           ];
         }