Commit | Line | Data |
---|---|---|
25523059 CW |
1 | <?php |
2 | ||
3 | require_once 'search.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_civicrm_config(&$config) { | |
11 | _search_civix_civicrm_config($config); | |
12 | } | |
13 | ||
14 | /** | |
15 | * Implements hook_civicrm_xmlMenu(). | |
16 | * | |
17 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu | |
18 | */ | |
19 | function search_civicrm_xmlMenu(&$files) { | |
20 | _search_civix_civicrm_xmlMenu($files); | |
21 | } | |
22 | ||
23 | /** | |
24 | * Implements hook_civicrm_install(). | |
25 | * | |
26 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install | |
27 | */ | |
28 | function search_civicrm_install() { | |
29 | _search_civix_civicrm_install(); | |
30 | } | |
31 | ||
32 | /** | |
33 | * Implements hook_civicrm_postInstall(). | |
34 | * | |
35 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall | |
36 | */ | |
37 | function search_civicrm_postInstall() { | |
38 | _search_civix_civicrm_postInstall(); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Implements hook_civicrm_uninstall(). | |
43 | * | |
44 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall | |
45 | */ | |
46 | function search_civicrm_uninstall() { | |
47 | _search_civix_civicrm_uninstall(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Implements hook_civicrm_enable(). | |
52 | * | |
53 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable | |
54 | */ | |
55 | function search_civicrm_enable() { | |
56 | _search_civix_civicrm_enable(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Implements hook_civicrm_disable(). | |
61 | * | |
62 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable | |
63 | */ | |
64 | function search_civicrm_disable() { | |
65 | _search_civix_civicrm_disable(); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Implements hook_civicrm_upgrade(). | |
70 | * | |
71 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade | |
72 | */ | |
73 | function search_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { | |
74 | return _search_civix_civicrm_upgrade($op, $queue); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Implements hook_civicrm_managed(). | |
79 | * | |
80 | * Generate a list of entities to create/deactivate/delete when this module | |
81 | * is installed, disabled, uninstalled. | |
82 | * | |
83 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed | |
84 | */ | |
85 | function search_civicrm_managed(&$entities) { | |
86 | _search_civix_civicrm_managed($entities); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Implements hook_civicrm_angularModules(). | |
91 | * | |
92 | * Generate a list of Angular modules. | |
93 | * | |
94 | * Note: This hook only runs in CiviCRM 4.5+. It may | |
95 | * use features only available in v4.6+. | |
96 | * | |
97 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules | |
98 | */ | |
99 | function search_civicrm_angularModules(&$angularModules) { | |
100 | _search_civix_civicrm_angularModules($angularModules); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Implements hook_civicrm_alterSettingsFolders(). | |
105 | * | |
106 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders | |
107 | */ | |
108 | function search_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { | |
109 | _search_civix_civicrm_alterSettingsFolders($metaDataFolders); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Implements hook_civicrm_entityTypes(). | |
114 | * | |
115 | * Declare entity types provided by this module. | |
116 | * | |
117 | * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes | |
118 | */ | |
119 | function search_civicrm_entityTypes(&$entityTypes) { | |
120 | _search_civix_civicrm_entityTypes($entityTypes); | |
121 | } | |
122 | ||
123 | /** | |
e991ce44 | 124 | * Implements hook_civicrm_themes(). |
25523059 CW |
125 | */ |
126 | function search_civicrm_themes(&$themes) { | |
127 | _search_civix_civicrm_themes($themes); | |
128 | } | |
e991ce44 CW |
129 | |
130 | /** | |
131 | * Implements hook_civicrm_pre(). | |
132 | */ | |
133 | function search_civicrm_pre($op, $entity, $id, &$params) { | |
134 | // Supply default name/label when creating new SearchDisplay | |
135 | if ($entity === 'SearchDisplay' && $op === 'create') { | |
136 | if (empty($params['label'])) { | |
137 | $params['label'] = $params['name']; | |
138 | } | |
139 | elseif (empty($params['name'])) { | |
140 | $params['name'] = \CRM_Utils_String::munge($params['label']); | |
141 | } | |
142 | } | |
143 | } | |
590c0e3f CW |
144 | |
145 | /** | |
146 | * Injects settings data to search displays embedded in afforms | |
147 | * | |
148 | * @param \Civi\Angular\Manager $angular | |
149 | * @see CRM_Utils_Hook::alterAngular() | |
150 | */ | |
151 | function search_civicrm_alterAngular($angular) { | |
152 | $changeSet = \Civi\Angular\ChangeSet::create('searchSettings') | |
153 | ->alterHtml(';\\.aff\\.html$;', function($doc, $path) { | |
e7515b5b | 154 | $displayTypes = array_column(\Civi\Search\Display::getDisplayTypes(['name']), 'name'); |
590c0e3f CW |
155 | |
156 | if ($displayTypes) { | |
157 | $componentNames = 'crm-search-display-' . implode(', crm-search-display-', $displayTypes); | |
158 | foreach (pq($componentNames, $doc) as $component) { | |
159 | $searchName = pq($component)->attr('search-name'); | |
160 | $displayName = pq($component)->attr('display-name'); | |
161 | if ($searchName && $displayName) { | |
162 | $display = \Civi\Api4\SearchDisplay::get(FALSE) | |
163 | ->addWhere('name', '=', $displayName) | |
164 | ->addWhere('saved_search.name', '=', $searchName) | |
165 | ->addSelect('settings', 'saved_search.api_entity', 'saved_search.api_params') | |
166 | ->execute()->first(); | |
167 | if ($display) { | |
168 | pq($component)->attr('settings', CRM_Utils_JS::encode($display['settings'] ?? [])); | |
169 | pq($component)->attr('api-entity', CRM_Utils_JS::encode($display['saved_search.api_entity'])); | |
170 | pq($component)->attr('api-params', CRM_Utils_JS::encode($display['saved_search.api_params'])); | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 | }); | |
176 | $angular->add($changeSet); | |
177 | ||
178 | } |