3 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
6 * The ExtensionUtil class provides small stubs for accessing resources of this
9 class CRM_Legacycustomsearches_ExtensionUtil
{
10 const SHORT_NAME
= 'legacycustomsearches';
11 const LONG_NAME
= 'legacycustomsearches';
12 const CLASS_PREFIX
= 'CRM_Legacycustomsearches';
15 * Translate a string using the extension's domain.
17 * If the extension doesn't have a specific translation
18 * for the string, fallback to the default translations.
21 * Canonical message text (generally en_US).
22 * @param array $params
27 public static function ts($text, $params = []) {
28 if (!array_key_exists('domain', $params)) {
29 $params['domain'] = [self
::LONG_NAME
, NULL];
31 return ts($text, $params);
35 * Get the URL of a resource file (in this extension).
37 * @param string|NULL $file
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'.
44 public static function url($file = NULL) {
46 return rtrim(CRM_Core_Resources
::singleton()->getUrl(self
::LONG_NAME
), '/');
48 return CRM_Core_Resources
::singleton()->getUrl(self
::LONG_NAME
, $file);
52 * Get the path of a resource file (in this extension).
54 * @param string|NULL $file
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'.
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));
67 * Get the name of a class within this extension.
69 * @param string $suffix
70 * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
72 * Ex: 'CRM_Foo_Page_HelloWorld'.
74 public static function findClass($suffix) {
75 return self
::CLASS_PREFIX
. '_' . str_replace('\\', '_', $suffix);
80 use CRM_Legacycustomsearches_ExtensionUtil
as E
;
83 * (Delegated) Implements hook_civicrm_config().
85 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
87 function _legacycustomsearches_civix_civicrm_config(&$config = NULL) {
88 static $configured = FALSE;
94 $template =& CRM_Core_Smarty
::singleton();
96 $extRoot = dirname(__FILE__
) . DIRECTORY_SEPARATOR
;
97 $extDir = $extRoot . 'templates';
99 if (is_array($template->template_dir
)) {
100 array_unshift($template->template_dir
, $extDir);
103 $template->template_dir
= [$extDir, $template->template_dir
];
106 $include_path = $extRoot . PATH_SEPARATOR
. get_include_path();
107 set_include_path($include_path);
111 * Implements hook_civicrm_install().
113 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
115 function _legacycustomsearches_civix_civicrm_install() {
116 _legacycustomsearches_civix_civicrm_config();
117 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
118 $upgrader->onInstall();
123 * Implements hook_civicrm_postInstall().
125 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
127 function _legacycustomsearches_civix_civicrm_postInstall() {
128 _legacycustomsearches_civix_civicrm_config();
129 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
130 if (is_callable([$upgrader, 'onPostInstall'])) {
131 $upgrader->onPostInstall();
137 * Implements hook_civicrm_uninstall().
139 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
141 function _legacycustomsearches_civix_civicrm_uninstall() {
142 _legacycustomsearches_civix_civicrm_config();
143 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
144 $upgrader->onUninstall();
149 * (Delegated) Implements hook_civicrm_enable().
151 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
153 function _legacycustomsearches_civix_civicrm_enable() {
154 _legacycustomsearches_civix_civicrm_config();
155 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
156 if (is_callable([$upgrader, 'onEnable'])) {
157 $upgrader->onEnable();
163 * (Delegated) Implements hook_civicrm_disable().
165 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
168 function _legacycustomsearches_civix_civicrm_disable() {
169 _legacycustomsearches_civix_civicrm_config();
170 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
171 if (is_callable([$upgrader, 'onDisable'])) {
172 $upgrader->onDisable();
178 * (Delegated) Implements hook_civicrm_upgrade().
180 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
181 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
184 * based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
185 * for 'enqueue', returns void
187 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
189 function _legacycustomsearches_civix_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
190 if ($upgrader = _legacycustomsearches_civix_upgrader()) {
191 return $upgrader->onUpgrade($op, $queue);
196 * @return CRM_Legacycustomsearches_Upgrader
198 function _legacycustomsearches_civix_upgrader() {
199 if (!file_exists(__DIR__
. '/CRM/Legacycustomsearches/Upgrader.php')) {
203 return CRM_Legacycustomsearches_Upgrader_Base
::instance();
208 * Search directory tree for files which match a glob pattern.
210 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
211 * Note: Delegate to CRM_Utils_File::findFiles(), this function kept only
212 * for backward compatibility of extension code that uses it.
214 * @param string $dir base dir
215 * @param string $pattern , glob pattern, eg "*.txt"
219 function _legacycustomsearches_civix_find_files($dir, $pattern) {
220 return CRM_Utils_File
::findFiles($dir, $pattern);
224 * (Delegated) Implements hook_civicrm_managed().
226 * Find any *.mgd.php files, merge their content, and return.
228 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
230 function _legacycustomsearches_civix_civicrm_managed(&$entities) {
231 $mgdFiles = _legacycustomsearches_civix_find_files(__DIR__
, '*.mgd.php');
233 foreach ($mgdFiles as $file) {
235 foreach ($es as $e) {
236 if (empty($e['module'])) {
237 $e['module'] = E
::LONG_NAME
;
239 if (empty($e['params']['version'])) {
240 $e['params']['version'] = '3';
248 * Glob wrapper which is guaranteed to return an array.
250 * The documentation for glob() says, "On some systems it is impossible to
251 * distinguish between empty match and an error." Anecdotally, the return
252 * result for an empty match is sometimes array() and sometimes FALSE.
253 * This wrapper provides consistency.
255 * @link http://php.net/glob
256 * @param string $pattern
260 function _legacycustomsearches_civix_glob($pattern) {
261 $result = glob($pattern);
262 return is_array($result) ?
$result : [];
266 * Inserts a navigation menu item at a given place in the hierarchy.
268 * @param array $menu - menu hierarchy
269 * @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
270 * 'Mailing', or 'Administer/System Settings'
271 * @param array $item - the item to insert (parent/child attributes will be
276 function _legacycustomsearches_civix_insert_navigation_menu(&$menu, $path, $item) {
277 // If we are done going down the path, insert menu
280 'attributes' => array_merge([
281 'label' => CRM_Utils_Array
::value('name', $item),
288 // Find an recurse into the next level down
290 $path = explode('/', $path);
291 $first = array_shift($path);
292 foreach ($menu as $key => &$entry) {
293 if ($entry['attributes']['name'] == $first) {
294 if (!isset($entry['child'])) {
295 $entry['child'] = [];
297 $found = _legacycustomsearches_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
305 * (Delegated) Implements hook_civicrm_navigationMenu().
307 function _legacycustomsearches_civix_navigationMenu(&$nodes) {
308 if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
309 _legacycustomsearches_civix_fixNavigationMenu($nodes);
314 * Given a navigation menu, generate navIDs for any items which are
317 function _legacycustomsearches_civix_fixNavigationMenu(&$nodes) {
319 array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
320 if ($key === 'navID') {
321 $maxNavID = max($maxNavID, $item);
324 _legacycustomsearches_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
327 function _legacycustomsearches_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
328 $origKeys = array_keys($nodes);
329 foreach ($origKeys as $origKey) {
330 if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
331 $nodes[$origKey]['attributes']['parentID'] = $parentID;
333 // If no navID, then assign navID and fix key.
334 if (!isset($nodes[$origKey]['attributes']['navID'])) {
335 $newKey = ++
$maxNavID;
336 $nodes[$origKey]['attributes']['navID'] = $newKey;
337 $nodes[$newKey] = $nodes[$origKey];
338 unset($nodes[$origKey]);
341 if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
342 _legacycustomsearches_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
348 * (Delegated) Implements hook_civicrm_entityTypes().
350 * Find any *.entityType.php files, merge their content, and return.
352 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
354 function _legacycustomsearches_civix_civicrm_entityTypes(&$entityTypes) {
355 $entityTypes = array_merge($entityTypes, []);