Add search/display details to searchKitTasks hook - allows for eg. filtering actions...
authorMatthew Wire <mjw@mjwconsult.co.uk>
Tue, 6 Dec 2022 22:31:58 +0000 (22:31 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Wed, 14 Dec 2022 18:29:41 +0000 (18:29 +0000)
ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js
ext/search_kit/search_kit.php

index c0f03105bce648433b0bc24c421d426579c9dfdf..0d00d08910864aa9f45f5a170f211dc1146be1d9 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Civi\Api4\Action\SearchDisplay;
 
+use Civi\Api4\Generic\Traits\SavedSearchInspectorTrait;
 use CRM_Search_ExtensionUtil as E;
 use Civi\Api4\Entity;
 
@@ -12,6 +13,14 @@ use Civi\Api4\Entity;
  */
 class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
 
+  use SavedSearchInspectorTrait;
+
+  /**
+   * An array containing the searchDisplay definition
+   * @var array
+   */
+  protected $display;
+
   /**
    * Name of entity
    * @var string
@@ -36,6 +45,10 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
     if (!$entity) {
       return;
     }
+
+    $this->loadSavedSearch();
+    $this->loadSearchDisplay();
+
     $tasks = [$entity['name'] => []];
 
     if (array_key_exists($entity['name'], \CRM_Export_BAO_Export::getComponents())) {
@@ -199,9 +212,9 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
     $null = NULL;
     $checkPermissions = $this->checkPermissions;
     $userId = $this->checkPermissions ? \CRM_Core_Session::getLoggedInContactID() : NULL;
-    \CRM_Utils_Hook::singleton()->invoke(['tasks', 'checkPermissions', 'userId'],
+    \CRM_Utils_Hook::singleton()->invoke(['tasks', 'checkPermissions', 'userId', 'search', 'display'],
       $tasks, $checkPermissions, $userId,
-      $null, $null, $null, 'civicrm_searchKitTasks'
+      $this->savedSearch, $this->display, $null, 'civicrm_searchKitTasks'
     );
 
     foreach ($tasks[$entity['name']] as $name => &$task) {
index 83d189c5d669724af76db7f9def77319fe403846..06c076561f972fe31c12d31e5fc896b9e7d38f2c 100644 (file)
@@ -31,7 +31,7 @@
         initialized = true;
         crmApi4({
           entityInfo: ['Entity', 'get', {select: ['name', 'title', 'title_plural', 'primary_key'], where: [['name', '=', ctrl.entity]]}, 0],
-          tasks: ['SearchDisplay', 'getSearchTasks', {entity: ctrl.entity}]
+          tasks: ['SearchDisplay', 'getSearchTasks', {entity: ctrl.entity, savedSearch: ctrl.search, display: ctrl.display}]
         }).then(function(result) {
           ctrl.entityInfo = result.entityInfo;
           ctrl.tasks = result.tasks;
index 68c46e97b01219260c3ae2a6b009e8f11c7c00f4..a17a0e35e9eff0b5a47c64f8f3d546e15c3274ea 100644 (file)
@@ -70,7 +70,7 @@ function search_kit_civicrm_angularModules(&$angularModules) {
   $tasks = [];
   $null = NULL;
   $checkPermissions = FALSE;
-  \CRM_Utils_Hook::singleton()->invoke(['tasks', 'checkPermissions', 'userId'],
+  \CRM_Utils_Hook::singleton()->invoke(['tasks', 'checkPermissions', 'userId', 'search', 'display'],
     $tasks, $checkPermissions, $null,
     $null, $null, $null, 'civicrm_searchKitTasks'
   );