Skip to content

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(&$tasks, $checkPermissions, $userId)

Parameters

  • $tasks (array) - the current set of tasks. You can add/remove existing tasks. Each task is an array and has keys like

    • title - title to display - remember to use ts() in core and E::ts() in extensions
    • icon - associated icon (optional)
    • uiDialog - array containing the path to the templateUrl
    • module - name of the angular module to require.

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 is true.

  • $userId (int|null) - If $checkPermissions is true, 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(&$tasks, $checkPermissions, $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 dedupeSearchTasks

(function(angular, $, _) {
    angular.module('dedupeSearchTasks', CRM.angRequires('dedupeSearchTasks'));
})(angular, CRM.$, CRM._);