Merge pull request #23697 from bsilvern/CRM-3495
[civicrm-core.git] / ext / payflowpro / payflowpro.civix.php
1 <?php
2
3 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
4
5 /**
6 * The ExtensionUtil class provides small stubs for accessing resources of this
7 * extension.
8 */
9 class CRM_Payflowpro_ExtensionUtil {
10 const SHORT_NAME = 'payflowpro';
11 const LONG_NAME = 'payflowpro';
12 const CLASS_PREFIX = 'CRM_Payflowpro';
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
80 use CRM_Payflowpro_ExtensionUtil as E;
81
82 /**
83 * (Delegated) Implements hook_civicrm_config().
84 *
85 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
86 */
87 function _payflowpro_civix_civicrm_config(&$config = NULL) {
88 static $configured = FALSE;
89 if ($configured) {
90 return;
91 }
92 $configured = TRUE;
93
94 $template = CRM_Core_Smarty::singleton();
95
96 $extRoot = __DIR__
97 . DIRECTORY_SEPARATOR;
98 $extDir = $extRoot . 'templates';
99
100 if (is_array($template->template_dir)) {
101 array_unshift($template->template_dir, $extDir);
102 }
103 else {
104 $template->template_dir = [$extDir, $template->template_dir];
105 }
106
107 $include_path = $extRoot . PATH_SEPARATOR . get_include_path();
108 set_include_path($include_path);
109 }
110
111 /**
112 * Implements hook_civicrm_install().
113 *
114 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
115 */
116 function _payflowpro_civix_civicrm_install() {
117 _payflowpro_civix_civicrm_config();
118 if ($upgrader = _payflowpro_civix_upgrader()) {
119 $upgrader->onInstall();
120 }
121 }
122
123 /**
124 * Implements hook_civicrm_postInstall().
125 *
126 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
127 */
128 function _payflowpro_civix_civicrm_postInstall() {
129 _payflowpro_civix_civicrm_config();
130 if ($upgrader = _payflowpro_civix_upgrader()) {
131 if (is_callable([$upgrader, 'onPostInstall'])) {
132 $upgrader->onPostInstall();
133 }
134 }
135 }
136
137 /**
138 * Implements hook_civicrm_uninstall().
139 *
140 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
141 */
142 function _payflowpro_civix_civicrm_uninstall() {
143 _payflowpro_civix_civicrm_config();
144 if ($upgrader = _payflowpro_civix_upgrader()) {
145 $upgrader->onUninstall();
146 }
147 }
148
149 /**
150 * (Delegated) Implements hook_civicrm_enable().
151 *
152 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
153 */
154 function _payflowpro_civix_civicrm_enable() {
155 _payflowpro_civix_civicrm_config();
156 if ($upgrader = _payflowpro_civix_upgrader()) {
157 if (is_callable([$upgrader, 'onEnable'])) {
158 $upgrader->onEnable();
159 }
160 }
161 }
162
163 /**
164 * (Delegated) Implements hook_civicrm_disable().
165 *
166 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
167 * @return mixed
168 */
169 function _payflowpro_civix_civicrm_disable() {
170 _payflowpro_civix_civicrm_config();
171 if ($upgrader = _payflowpro_civix_upgrader()) {
172 if (is_callable([$upgrader, 'onDisable'])) {
173 $upgrader->onDisable();
174 }
175 }
176 }
177
178 /**
179 * (Delegated) Implements hook_civicrm_upgrade().
180 *
181 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
182 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
183 *
184 * @return mixed
185 * based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
186 * for 'enqueue', returns void
187 *
188 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
189 */
190 function _payflowpro_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
191 if ($upgrader = _payflowpro_civix_upgrader()) {
192 return $upgrader->onUpgrade($op, $queue);
193 }
194 }
195
196 /**
197 * @return CRM_Payflowpro_Upgrader
198 */
199 function _payflowpro_civix_upgrader() {
200 if (!file_exists(__DIR__ . '/CRM/Payflowpro/Upgrader.php')) {
201 return NULL;
202 }
203 else {
204 return CRM_Payflowpro_Upgrader_Base::instance();
205 }
206 }
207
208 /**
209 * Inserts a navigation menu item at a given place in the hierarchy.
210 *
211 * @param array $menu - menu hierarchy
212 * @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
213 * 'Mailing', or 'Administer/System Settings'
214 * @param array $item - the item to insert (parent/child attributes will be
215 * filled for you)
216 *
217 * @return bool
218 */
219 function _payflowpro_civix_insert_navigation_menu(&$menu, $path, $item) {
220 // If we are done going down the path, insert menu
221 if (empty($path)) {
222 $menu[] = [
223 'attributes' => array_merge([
224 'label' => CRM_Utils_Array::value('name', $item),
225 'active' => 1,
226 ], $item),
227 ];
228 return TRUE;
229 }
230 else {
231 // Find an recurse into the next level down
232 $found = FALSE;
233 $path = explode('/', $path);
234 $first = array_shift($path);
235 foreach ($menu as $key => &$entry) {
236 if ($entry['attributes']['name'] == $first) {
237 if (!isset($entry['child'])) {
238 $entry['child'] = [];
239 }
240 $found = _payflowpro_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item);
241 }
242 }
243 return $found;
244 }
245 }
246
247 /**
248 * (Delegated) Implements hook_civicrm_navigationMenu().
249 */
250 function _payflowpro_civix_navigationMenu(&$nodes) {
251 if (!is_callable(['CRM_Core_BAO_Navigation', 'fixNavigationMenu'])) {
252 _payflowpro_civix_fixNavigationMenu($nodes);
253 }
254 }
255
256 /**
257 * Given a navigation menu, generate navIDs for any items which are
258 * missing them.
259 */
260 function _payflowpro_civix_fixNavigationMenu(&$nodes) {
261 $maxNavID = 1;
262 array_walk_recursive($nodes, function($item, $key) use (&$maxNavID) {
263 if ($key === 'navID') {
264 $maxNavID = max($maxNavID, $item);
265 }
266 });
267 _payflowpro_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL);
268 }
269
270 function _payflowpro_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
271 $origKeys = array_keys($nodes);
272 foreach ($origKeys as $origKey) {
273 if (!isset($nodes[$origKey]['attributes']['parentID']) && $parentID !== NULL) {
274 $nodes[$origKey]['attributes']['parentID'] = $parentID;
275 }
276 // If no navID, then assign navID and fix key.
277 if (!isset($nodes[$origKey]['attributes']['navID'])) {
278 $newKey = ++$maxNavID;
279 $nodes[$origKey]['attributes']['navID'] = $newKey;
280 $nodes[$newKey] = $nodes[$origKey];
281 unset($nodes[$origKey]);
282 $origKey = $newKey;
283 }
284 if (isset($nodes[$origKey]['child']) && is_array($nodes[$origKey]['child'])) {
285 _payflowpro_civix_fixNavigationMenuItems($nodes[$origKey]['child'], $maxNavID, $nodes[$origKey]['attributes']['navID']);
286 }
287 }
288 }
289
290 /**
291 * (Delegated) Implements hook_civicrm_entityTypes().
292 *
293 * Find any *.entityType.php files, merge their content, and return.
294 *
295 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
296 */
297 function _payflowpro_civix_civicrm_entityTypes(&$entityTypes) {
298 $entityTypes = array_merge($entityTypes, []);
299 }