hook_civicrm_searchKitTasks¶
Summary¶
This hook is called to allow you to add to or alter the tasks available in search kit.
Definition¶
hook_civicrm_searchKitTasks(array &$tasks, bool $checkPermissions, ?int $userID)
Parameters¶
-
$tasks
(array) - the current set of tasks. You can add/remove existing tasks. Each task is an array and has keys liketitle
- title to display - remember to use ts() in core and E::ts() in extensionsicon
- associated icon (optional)uiDialog
- array containing the path to the templateUrlmodule
- name of the angular module to require.apiBatch
- (from 5.56) array describing the action if you are not providing a form (if you just want a generic UI). Has the keys:action
- Name of API action to call once per rowparams
- Optional array of additional api paramsconfirmMsg
- If omitted, the action will run immediately with no confirmationrunMsg
successMsg
,errorMsg
,
Note: the $tasks
array is keyed by the entity that it applies to. Depending on context, the array may or may not already be populated with some data. Your hook implementation should add its tasks regardless of what's already in the array.
-
$checkPermissions
(boolean) - Whether permissions ought to be taken into account. If the tasks you are adding shouldn't be available to all users, perform any necessary permission checks only if this value istrue
. -
$userID
(int|null) - If$checkPermissions
istrue
, will contain the contact ID of the acting user.
Returns¶
- null
Example (Add a new task)¶
/**
* Implements hook_civicrm_searchKitTasks().
*
* @param array[] $tasks
* @param bool $checkPermissions
* @param int|null $userID
*/
function deduper_civicrm_searchKitTasks(array &$tasks, bool $checkPermissions, ?int $userID) {
$tasks['Contact']['flip'] = [
'module' => 'dedupeSearchTasks',
'title' => E::ts('Flip first/last name'),
'icon' => 'fa-random',
'uiDialog' => ['templateUrl' => '~/dedupeSearchTasks/dedupeSearchTaskFlip.html'],
];
}
This would have a js & a php file ang/dedupeSearchTasks.js that declares the module.
These can be generated using civix - eg. civix generate:angular-module --am=dedupeSearchTasks
(function(angular, $, _) {
angular.module('dedupeSearchTasks', CRM.angRequires('dedupeSearchTasks'));
})(angular, CRM.$, CRM._);