Remove deprecated language construct
[civicrm-core.git] / tools / extensions / org.civicrm.angularex / angularex.civix.php
CommitLineData
b3acfd03
TO
1<?php
2
3// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
4
5/**
7980012b
SL
6 * The ExtensionUtil class provides small stubs for accessing resources of this
7 * extension.
8 */
9class CRM_Angularex_ExtensionUtil {
10 const SHORT_NAME = "angularex";
11 const LONG_NAME = "org.civicrm.angularex";
12 const CLASS_PREFIX = "CRM_Angularex";
13
14 /**
15 * Translate a string using the extension's domain.
16 *
17 * If the extension doesn't have a specific translation
18 * for the string, fallback to the default translations.
19 *
20 * @param string $text
21 * Canonical message text (generally en_US).
22 * @param array $params
23 * @return string
24 * Translated text.
25 * @see ts
26 */
27 public static function ts($text, $params = []) {
28 if (!array_key_exists('domain', $params)) {
29 $params['domain'] = [self::LONG_NAME, NULL];
30 }
31 return ts($text, $params);
32 }
33
34 /**
35 * Get the URL of a resource file (in this extension).
36 *
37 * @param string|NULL $file
38 * Ex: NULL.
39 * Ex: 'css/foo.css'.
40 * @return string
41 * Ex: 'http://example.org/sites/default/ext/org.example.foo'.
42 * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
43 */
44 public static function url($file = NULL) {
45 if ($file === NULL) {
46 return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/');
47 }
48 return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file);
49 }
50
51 /**
52 * Get the path of a resource file (in this extension).
53 *
54 * @param string|NULL $file
55 * Ex: NULL.
56 * Ex: 'css/foo.css'.
57 * @return string
58 * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
59 * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
60 */
61 public static function path($file = NULL) {
62 // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
63 return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file));
64 }
65
66 /**
67 * Get the name of a class within this extension.
68 *
69 * @param string $suffix
70 * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
71 * @return string
72 * Ex: 'CRM_Foo_Page_HelloWorld'.
73 */
74 public static function findClass($suffix) {
75 return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix);
76 }
77
78}
79
80use CRM_Angularex_ExtensionUtil as E;
81
82/**
83 * (Delegated) Implements hook_civicrm_config().
b3acfd03 84 *
7980012b 85 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
b3acfd03
TO
86 */
87function _angularex_civix_civicrm_config(&$config = NULL) {
88 static $configured = FALSE;
b7c0a88f 89 if ($configured) {
90 return;
91 }
b3acfd03
TO
92 $configured = TRUE;
93
6f2b0555 94 $template = CRM_Core_Smarty::singleton();
b3acfd03 95
6f2b0555 96 $extRoot = __DIR__ . DIRECTORY_SEPARATOR;
b3acfd03
TO
97 $extDir = $extRoot . 'templates';
98
b7c0a88f 99 if (is_array($template->template_dir)) {
100 array_unshift($template->template_dir, $extDir);
101 }
102 else {
103 $template->template_dir = [$extDir, $template->template_dir];
b3acfd03
TO
104 }
105
b7c0a88f 106 $include_path = $extRoot . PATH_SEPARATOR . get_include_path();
107 set_include_path($include_path);
b3acfd03
TO
108}
109
110/**
7980012b 111 * (Delegated) Implements hook_civicrm_xmlMenu().
b3acfd03
TO
112 *
113 * @param $files array(string)
7980012b
SL
114 *
115 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
b3acfd03
TO
116 */
117function _angularex_civix_civicrm_xmlMenu(&$files) {
118 foreach (_angularex_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
119 $files[] = $file;
120 }
121}
122
123/**
7980012b 124 * Implements hook_civicrm_install().
b3acfd03 125 *
7980012b 126 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
b3acfd03
TO
127 */
128function _angularex_civix_civicrm_install() {
129 _angularex_civix_civicrm_config();
130 if ($upgrader = _angularex_civix_upgrader()) {
7980012b 131 $upgrader->onInstall();
b3acfd03
TO
132 }
133}
134
135/**
7980012b 136 * Implements hook_civicrm_postInstall().
b3acfd03 137 *
7980012b
SL
138 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
139 */
140function _angularex_civix_civicrm_postInstall() {
141 _angularex_civix_civicrm_config();
142 if ($upgrader = _angularex_civix_upgrader()) {
143 if (is_callable([$upgrader, 'onPostInstall'])) {
144 $upgrader->onPostInstall();
145 }
146 }
147}
148
149/**
150 * Implements hook_civicrm_uninstall().
151 *
152 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
b3acfd03
TO
153 */
154function _angularex_civix_civicrm_uninstall() {
155 _angularex_civix_civicrm_config();
156 if ($upgrader = _angularex_civix_upgrader()) {
7980012b 157 $upgrader->onUninstall();
b3acfd03
TO
158 }
159}
160
161/**
7980012b 162 * (Delegated) Implements hook_civicrm_enable().
b3acfd03 163 *
7980012b 164 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
b3acfd03
TO
165 */
166function _angularex_civix_civicrm_enable() {
167 _angularex_civix_civicrm_config();
168 if ($upgrader = _angularex_civix_upgrader()) {
b7c0a88f 169 if (is_callable([$upgrader, 'onEnable'])) {
7980012b 170 $upgrader->onEnable();
b3acfd03
TO
171 }
172 }
173}
174
175/**
7980012b 176 * (Delegated) Implements hook_civicrm_disable().
b3acfd03 177 *
7980012b
SL
178 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
179 * @return mixed
b3acfd03
TO
180 */
181function _angularex_civix_civicrm_disable() {
182 _angularex_civix_civicrm_config();
183 if ($upgrader = _angularex_civix_upgrader()) {
b7c0a88f 184 if (is_callable([$upgrader, 'onDisable'])) {
7980012b 185 $upgrader->onDisable();
b3acfd03
TO
186 }
187 }
188}
189
190/**
7980012b 191 * (Delegated) Implements hook_civicrm_upgrade().
b3acfd03
TO
192 *
193 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
194 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
195 *
196 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
197 * for 'enqueue', returns void
198 *
7980012b 199 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
b3acfd03
TO
200 */
201function _angularex_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
202 if ($upgrader = _angularex_civix_upgrader()) {
203 return $upgrader->onUpgrade($op, $queue);
204 }
205}
206
207/**
208 * @return CRM_Angularex_Upgrader
209 */
210function _angularex_civix_upgrader() {
b7c0a88f 211 if (!file_exists(__DIR__ . '/CRM/Angularex/Upgrader.php')) {
b3acfd03 212 return NULL;
b7c0a88f 213 }
214 else {
b3acfd03
TO
215 return CRM_Angularex_Upgrader_Base::instance();
216 }
217}
218
219/**
7980012b 220 * Search directory tree for files which match a glob pattern.
b3acfd03
TO
221 *
222 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
223 * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
224 *
7980012b
SL
225 * @param string $dir base dir
226 * @param string $pattern , glob pattern, eg "*.txt"
227 *
b3acfd03
TO
228 * @return array(string)
229 */
230function _angularex_civix_find_files($dir, $pattern) {
b7c0a88f 231 if (is_callable(['CRM_Utils_File', 'findFiles'])) {
b3acfd03
TO
232 return CRM_Utils_File::findFiles($dir, $pattern);
233 }
234
b7c0a88f 235 $todos = [$dir];
236 $result = [];
b3acfd03
TO
237 while (!empty($todos)) {
238 $subdir = array_shift($todos);
239 foreach (_angularex_civix_glob("$subdir/$pattern") as $match) {
240 if (!is_dir($match)) {
241 $result[] = $match;
242 }
243 }
244 if ($dh = opendir($subdir)) {
245 while (FALSE !== ($entry = readdir($dh))) {
246 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
247 if ($entry{0} == '.') {
b7c0a88f 248 }
249 elseif (is_dir($path)) {
b3acfd03
TO
250 $todos[] = $path;
251 }
252 }
253 closedir($dh);
254 }
255 }
256 return $result;
257}
258/**
7980012b 259 * (Delegated) Implements hook_civicrm_managed().
b3acfd03
TO
260 *
261 * Find any *.mgd.php files, merge their content, and return.
262 *
7980012b 263 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
b3acfd03
TO
264 */
265function _angularex_civix_civicrm_managed(&$entities) {
266 $mgdFiles = _angularex_civix_find_files(__DIR__, '*.mgd.php');
7980012b 267 sort($mgdFiles);
b3acfd03
TO
268 foreach ($mgdFiles as $file) {
269 $es = include $file;
270 foreach ($es as $e) {
271 if (empty($e['module'])) {
7980012b
SL
272 $e['module'] = E::LONG_NAME;
273 }
274 if (empty($e['params']['version'])) {
275 $e['params']['version'] = '3';
b3acfd03
TO
276 }
277 $entities[] = $e;
278 }
279 }
280}
281
282/**
7980012b 283 * (Delegated) Implements hook_civicrm_caseTypes().
b3acfd03
TO
284 *
285 * Find any and return any files matching "xml/case/*.xml"
286 *
287 * Note: This hook only runs in CiviCRM 4.4+.
288 *
7980012b 289 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
b3acfd03
TO
290 */
291function _angularex_civix_civicrm_caseTypes(&$caseTypes) {
292 if (!is_dir(__DIR__ . '/xml/case')) {
293 return;
294 }
295
296 foreach (_angularex_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) {
297 $name = preg_replace('/\.xml$/', '', basename($file));
298 if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) {
299 $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name));
7980012b 300 throw new CRM_Core_Exception($errorMessage);
b3acfd03 301 }
b7c0a88f 302 $caseTypes[$name] = [
7980012b 303 'module' => E::LONG_NAME,
b3acfd03
TO
304 'name' => $name,
305 'file' => $file,
b7c0a88f 306 ];
b3acfd03
TO
307 }
308}
309
7980012b
SL
310/**
311 * (Delegated) Implements hook_civicrm_angularModules().
312 *
313 * Find any and return any files matching "ang/*.ang.php"
314 *
315 * Note: This hook only runs in CiviCRM 4.5+.
316 *
317 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
318 */
319function _angularex_civix_civicrm_angularModules(&$angularModules) {
320 if (!is_dir(__DIR__ . '/ang')) {
321 return;
322 }
323
324 $files = _angularex_civix_glob(__DIR__ . '/ang/*.ang.php');
325 foreach ($files as $file) {
326 $name = preg_replace(':\.ang\.php$:', '', basename($file));
327 $module = include $file;
328 if (empty($module['ext'])) {
329 $module['ext'] = E::LONG_NAME;
330 }
331 $angularModules[$name] = $module;
332 }
333}
334
335/**
336 * (Delegated) Implements hook_civicrm_themes().
337 *
338 * Find any and return any files matching "*.theme.php"
339 */
340function _angularex_civix_civicrm_themes(&$themes) {
341 $files = _angularex_civix_glob(__DIR__ . '/*.theme.php');
342 foreach ($files as $file) {
343 $themeMeta = include $file;
344 if (empty($themeMeta['name'])) {
345 $themeMeta['name'] = preg_replace(':\.theme\.php$:', '', basename($file));
346 }
347 if (empty($themeMeta['ext'])) {
348 $themeMeta['ext'] = E::LONG_NAME;
349 }
350 $themes[$themeMeta['name']] = $themeMeta;
351 }
352}
353
b3acfd03
TO
354/**
355 * Glob wrapper which is guaranteed to return an array.
356 *
357 * The documentation for glob() says, "On some systems it is impossible to
358 * distinguish between empty match and an error." Anecdotally, the return
359 * result for an empty match is sometimes array() and sometimes FALSE.
360 * This wrapper provides consistency.
361 *
362 * @link http://php.net/glob
363 * @param string $pattern
7980012b 364 *
b3acfd03
TO
365 * @return array, possibly empty
366 */
367function _angularex_civix_glob($pattern) {
368 $result = glob($pattern);
b7c0a88f 369 return is_array($result) ? $result : [];
b3acfd03
TO
370}
371
372/**
7980012b
SL
373 * Inserts a navigation menu item at a given place in the hierarchy.
374 *
375 * @param array $menu - menu hierarchy
376 * @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
377 * 'Mailing', or 'Administer/System Settings'
378 * @param array $item - the item to insert (parent/child attributes will be
379 * filled for you)
b3acfd03 380 *
d7c8cf03 381 * @return bool
b3acfd03 382 */
7980012b 383function _angularex_civix_insert_navigation_menu(&$menu, $path, $item) {
b3acfd03
TO
384 // If we are done going down the path, insert menu
385 if (empty($path)) {
7980012b
SL
386 $menu[] = [
387 'attributes' => array_merge([
388 'label' => CRM_Utils_Array::value('name', $item),
389 'active' => 1,
390 ], $item),
b7c0a88f 391 ];
392 return TRUE;
393 }
394 else {
b3acfd03 395 // Find an recurse into the next level down
b7c0a88f 396 $found = FALSE;
b3acfd03
TO
397 $path = explode('/', $path);
398 $first = array_shift($path);
399 foreach ($menu as $key => &$entry) {
400 if ($entry['attributes']['name'] == $first) {
7980012b 401 if (!isset($entry['child'])) {
b7c0a88f 402 $entry['child'] = [];
403 }
7980012b 404 $found = _angularex_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
b3acfd03
TO
405 }
406 }
407 return $found;
408 }
409}
410
411/**
7980012b 412 * (Delegated) Implements hook_civicrm_navigationMenu().
b3acfd03 413 */
7980012b
SL
414function _angularex_civix_navigationMenu(&$nodes) {
415 if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
416 _angularex_civix_fixNavigationMenu($nodes);
b7c0a88f 417 }
7980012b 418}
b3acfd03 419
7980012b
SL
420/**
421 * Given a navigation menu, generate navIDs for any items which are
422 * missing them.
423 */
424function _angularex_civix_fixNavigationMenu(&$nodes) {
425 $maxNavID = 1;
426 array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
427 if ($key === 'navID') {
428 $maxNavID = max($maxNavID, $item);
429 }
430 });
431 _angularex_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
432}
433
434function _angularex_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
435 $origKeys = array_keys($nodes);
436 foreach ($origKeys as $origKey) {
437 if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
438 $nodes[$origKey]['attributes']['parentID'] = $parentID;
439 }
440 // If no navID, then assign navID and fix key.
441 if (!isset($nodes[$origKey]['attributes']['navID'])) {
442 $newKey = ++$maxNavID;
443 $nodes[$origKey]['attributes']['navID'] = $newKey;
444 $nodes[$newKey] = $nodes[$origKey];
445 unset($nodes[$origKey]);
446 $origKey = $newKey;
447 }
448 if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
449 _angularex_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
450 }
451 }
452}
453
454/**
455 * (Delegated) Implements hook_civicrm_alterSettingsFolders().
456 *
457 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
458 */
459function _angularex_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
b3acfd03 460 $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings';
7980012b 461 if (!in_array($settingsDir, $metaDataFolders) && is_dir($settingsDir)) {
b3acfd03
TO
462 $metaDataFolders[] = $settingsDir;
463 }
d7c8cf03 464}
7980012b
SL
465
466/**
467 * (Delegated) Implements hook_civicrm_entityTypes().
468 *
469 * Find any *.entityType.php files, merge their content, and return.
470 *
471 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
472 */
473
474function _angularex_civix_civicrm_entityTypes(&$entityTypes) {
475 $entityTypes = array_merge($entityTypes, array (
476 ));
477}