mixin/ang-php - Import
authorTim Otten <totten@civicrm.org>
Tue, 30 Nov 2021 22:26:11 +0000 (14:26 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 7 Dec 2021 00:05:51 +0000 (16:05 -0800)
mixin/ang-php@1/mixin.php [new file with mode: 0644]

diff --git a/mixin/ang-php@1/mixin.php b/mixin/ang-php@1/mixin.php
new file mode 100644 (file)
index 0000000..6719db3
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Auto-register "ang/*.ang.php" files.
+ *
+ * @mixinName ang-php
+ * @mixinVersion 1.0.0
+ *
+ * @param CRM_Extension_MixInfo $mixInfo
+ *   On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
+ * @param \CRM_Extension_BootCache $bootCache
+ *   On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like.
+ */
+return function ($mixInfo, $bootCache) {
+
+  /**
+   * @param \Civi\Core\Event\GenericHookEvent $e
+   * @see CRM_Utils_Hook::angularModules()
+   */
+  Civi::dispatcher()->addListener('hook_civicrm_angularModules', function ($e) use ($mixInfo) {
+    // When deactivating on a polyfill/pre-mixin system, listeners may not cleanup automatically.
+    if (!$mixInfo->isActive() || !is_dir($mixInfo->getPath('ang'))) {
+      return;
+    }
+
+    $files = (array) glob($mixInfo->getPath('ang/*.ang.php'));
+    foreach ($files as $file) {
+      $name = preg_replace(':\.ang\.php$:', '', basename($file));
+      $module = include $file;
+      if (empty($module['ext'])) {
+        $module['ext'] = $mixInfo->longName;
+      }
+      $e->angularModules[$name] = $module;
+    }
+  });
+
+};