Merge pull request #23374 from eileenmcnaughton/549_up
[civicrm-core.git] / mixin / mgd-php@1 / mixin.php
1 <?php
2
3 /**
4 * Auto-register "**.mgd.php" files.
5 *
6 * @mixinName mgd-php
7 * @mixinVersion 1.0.0
8 *
9 * @param CRM_Extension_MixInfo $mixInfo
10 * On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
11 * @param \CRM_Extension_BootCache $bootCache
12 * On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
13 */
14 return function ($mixInfo, $bootCache) {
15
16 /**
17 * @param \Civi\Core\Event\GenericHookEvent $e
18 * @see CRM_Utils_Hook::managed()
19 */
20 Civi::dispatcher()->addListener('hook_civicrm_managed', function ($event) use ($mixInfo) {
21 // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
22 if (!$mixInfo->isActive()) {
23 return;
24 }
25
26 if (is_array($event->modules) && !in_array($mixInfo->longName, $event->modules, TRUE)) {
27 return;
28 }
29
30 $mgdFiles = CRM_Utils_File::findFiles($mixInfo->getPath(), '*.mgd.php');
31 sort($mgdFiles);
32 foreach ($mgdFiles as $file) {
33 $es = include $file;
34 foreach ($es as $e) {
35 if (empty($e['module'])) {
36 $e['module'] = $mixInfo->longName;
37 }
38 if (empty($e['params']['version'])) {
39 $e['params']['version'] = '3';
40 }
41 $event->entities[] = $e;
42 }
43 }
44 });
45
46 };