From 9ef3074941fb3c0e5d41f60e68676b8695462312 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 6 Dec 2022 22:31:58 +0000 Subject: [PATCH] Add search/display details to searchKitTasks hook - allows for eg. filtering actions by search display --- .../Action/SearchDisplay/GetSearchTasks.php | 17 +++++++++++++++-- .../crmSearchTasks/crmSearchTasks.component.js | 2 +- ext/search_kit/search_kit.php | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php index c0f03105bc..0d00d08910 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php @@ -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) { diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js index 83d189c5d6..06c076561f 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js @@ -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; diff --git a/ext/search_kit/search_kit.php b/ext/search_kit/search_kit.php index 68c46e97b0..a17a0e35e9 100644 --- a/ext/search_kit/search_kit.php +++ b/ext/search_kit/search_kit.php @@ -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' ); -- 2.25.1