[NFC] Do not generate a result cache file when running legacycustomsearches phpunit...
[civicrm-core.git] / ext / search_kit / search_kit.php
1 <?php
2
3 require_once 'search_kit.civix.php';
4
5 /**
6 * Implements hook_civicrm_config().
7 *
8 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
9 */
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);
13 }
14
15 /**
16 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
17 */
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'],
23 ]);
24 }
25
26 /**
27 * Implements hook_civicrm_xmlMenu().
28 *
29 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
30 */
31 function search_kit_civicrm_xmlMenu(&$files) {
32 _search_kit_civix_civicrm_xmlMenu($files);
33 }
34
35 /**
36 * Implements hook_civicrm_managed().
37 *
38 * Generate a list of entities to create/deactivate/delete when this module
39 * is installed, disabled, uninstalled.
40 *
41 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
42 */
43 function search_kit_civicrm_managed(&$entities) {
44 _search_kit_civix_civicrm_managed($entities);
45 }
46
47 /**
48 * Implements hook_civicrm_angularModules().
49 *
50 * Generate a list of Angular modules.
51 *
52 * Note: This hook only runs in CiviCRM 4.5+. It may
53 * use features only available in v4.6+.
54 *
55 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
56 */
57 function search_kit_civicrm_angularModules(&$angularModules) {
58 _search_kit_civix_civicrm_angularModules($angularModules);
59 // Fetch all search tasks provided by extensions and add their Angular modules as crmSearchTasks dependencies
60 $tasks = [];
61 $null = NULL;
62 $checkPermissions = FALSE;
63 \CRM_Utils_Hook::singleton()->invoke(['tasks', 'checkPermissions', 'userId'],
64 $tasks, $checkPermissions, $null,
65 $null, $null, $null, 'civicrm_searchKitTasks'
66 );
67 foreach ($tasks as $entityTasks) {
68 foreach ($entityTasks as $task) {
69 if (isset($task['module']) && $task['module'] !== 'crmSearchTasks' &&
70 !in_array($task['module'], $angularModules['crmSearchTasks']['requires'], TRUE)
71 ) {
72 $angularModules['crmSearchTasks']['requires'][] = $task['module'];
73 }
74 }
75 }
76 }
77
78 /**
79 * Implements hook_civicrm_alterSettingsFolders().
80 *
81 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
82 */
83 function search_kit_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
84 _search_kit_civix_civicrm_alterSettingsFolders($metaDataFolders);
85 }
86
87 /**
88 * Implements hook_civicrm_entityTypes().
89 *
90 * Declare entity types provided by this module.
91 *
92 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
93 */
94 function search_kit_civicrm_entityTypes(&$entityTypes) {
95 _search_kit_civix_civicrm_entityTypes($entityTypes);
96 }
97
98 /**
99 * Implements hook_civicrm_themes().
100 */
101 function search_kit_civicrm_themes(&$themes) {
102 _search_kit_civix_civicrm_themes($themes);
103 }
104
105 /**
106 * Implements hook_civicrm_pre().
107 */
108 function search_kit_civicrm_pre($op, $entity, $id, &$params) {
109 // Supply default name/label when creating new SearchDisplay
110 if ($entity === 'SearchDisplay' && $op === 'create') {
111 if (empty($params['label'])) {
112 $params['label'] = $params['name'];
113 }
114 elseif (empty($params['name'])) {
115 $params['name'] = \CRM_Utils_String::munge($params['label']);
116 }
117 }
118 }