3 require_once 'search_kit.civix.php';
6 * Implements hook_civicrm_config().
8 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
10 function search_kit_civicrm_config(&$config) {
11 _search_kit_civix_civicrm_config($config);
12 Civi
::dispatcher()->addListener('hook_civicrm_alterAngular', ['\Civi\Search\AfformSearchMetadataInjector', 'preprocess'], 1000);
16 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
18 function search_kit_civicrm_container($container) {
19 $container->getDefinition('dispatcher')
20 ->addMethodCall('addListener', [
21 'civi.api4.authorizeRecord::SavedSearch',
22 ['CRM_Search_BAO_SearchDisplay', 'savedSearchCheckAccessByDisplay'],
27 * Implements hook_civicrm_alterApiRoutePermissions().
29 * Allow anonymous users to run a search display. Permissions are checked internally.
31 * @see CRM_Utils_Hook::alterApiRoutePermissions
33 function search_kit_civicrm_alterApiRoutePermissions(&$permissions, $entity, $action) {
34 if ($entity === 'SearchDisplay') {
35 if ($action === 'run' ||
$action === 'download' ||
$action === 'getSearchTasks') {
36 $permissions = CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
;
42 * Implements hook_civicrm_xmlMenu().
44 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
46 function search_kit_civicrm_xmlMenu(&$files) {
47 _search_kit_civix_civicrm_xmlMenu($files);
51 * Implements hook_civicrm_managed().
53 * Generate a list of entities to create/deactivate/delete when this module
54 * is installed, disabled, uninstalled.
56 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
58 function search_kit_civicrm_managed(&$entities) {
59 _search_kit_civix_civicrm_managed($entities);
63 * Implements hook_civicrm_angularModules().
65 * Generate a list of Angular modules.
67 * Note: This hook only runs in CiviCRM 4.5+. It may
68 * use features only available in v4.6+.
70 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
72 function search_kit_civicrm_angularModules(&$angularModules) {
73 _search_kit_civix_civicrm_angularModules($angularModules);
74 // Fetch all search tasks provided by extensions and add their Angular modules as crmSearchTasks dependencies
77 $checkPermissions = FALSE;
78 \CRM_Utils_Hook
::singleton()->invoke(['tasks', 'checkPermissions', 'userId'],
79 $tasks, $checkPermissions, $null,
80 $null, $null, $null, 'civicrm_searchKitTasks'
82 foreach ($tasks as $entityTasks) {
83 foreach ($entityTasks as $task) {
84 if (isset($task['module']) && $task['module'] !== 'crmSearchTasks' &&
85 !in_array($task['module'], $angularModules['crmSearchTasks']['requires'], TRUE)
87 $angularModules['crmSearchTasks']['requires'][] = $task['module'];
94 * Implements hook_civicrm_alterSettingsFolders().
96 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
98 function search_kit_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
99 _search_kit_civix_civicrm_alterSettingsFolders($metaDataFolders);
103 * Implements hook_civicrm_entityTypes().
105 * Declare entity types provided by this module.
107 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
109 function search_kit_civicrm_entityTypes(&$entityTypes) {
110 _search_kit_civix_civicrm_entityTypes($entityTypes);
114 * Implements hook_civicrm_themes().
116 function search_kit_civicrm_themes(&$themes) {
117 _search_kit_civix_civicrm_themes($themes);
121 * Implements hook_civicrm_pre().
123 function search_kit_civicrm_pre($op, $entity, $id, &$params) {
124 // Supply default name/label when creating new SearchDisplay
125 if ($entity === 'SearchDisplay' && $op === 'create') {
126 if (empty($params['label'])) {
127 $params['label'] = $params['name'];
129 elseif (empty($params['name'])) {
130 $params['name'] = \CRM_Utils_String
::munge($params['label']);
133 // When deleting a saved search, also delete the displays
134 // This would happen anyway in sql because of the ON DELETE CASCADE foreign key,
135 // But this ensures that pre and post hooks are called
136 if ($entity === 'SavedSearch' && $op === 'delete') {
137 \Civi\Api4\SearchDisplay
::delete(FALSE)
138 ->addWhere('saved_search_id', '=', $id)