Afform - Fix scanning for input types
authorColeman Watts <coleman@civicrm.org>
Fri, 8 Jan 2021 20:20:59 +0000 (15:20 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 11 Jan 2021 14:49:06 +0000 (09:49 -0500)
ext/afform/admin/CRM/AfformAdmin/Utils.php

index f34f739b4fbfd640934f054be9a5845822cc96ff..00cf47ba82b53795fd900b51c90dfad46d9b2547 100644 (file)
@@ -31,11 +31,12 @@ class CRM_AfformAdmin_Utils {
 
     $contactTypes = CRM_Contact_BAO_ContactType::basicTypeInfo();
 
-    // Scan all extensions for our list of supported entities
+    // Scan all extensions for entities & input types
     foreach (CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles() as $ext) {
-      $dir = CRM_Utils_File::addTrailingSlash(dirname($ext['filePath'])) . 'afformEntities';
+      $dir = CRM_Utils_File::addTrailingSlash(dirname($ext['filePath']));
       if (is_dir($dir)) {
-        foreach (glob($dir . '/*.php') as $file) {
+        // Scan for entities
+        foreach (glob($dir . 'afformEntities/*.php') as $file) {
           $entity = include $file;
           // Skip disabled contact types
           if (!empty($entity['contact_type']) && !isset($contactTypes[$entity['contact_type']])) {
@@ -50,6 +51,12 @@ class CRM_AfformAdmin_Utils {
           $entity['fields'] = (array) civicrm_api4($entity['entity'], 'getFields', $getFieldParams + ['values' => $values], 'name');
           $data['entities'][$afformEntity] = $entity;
         }
+        // Scan for input types
+        foreach (glob($dir . 'ang/afGuiEditor/inputType/*.html') as $file) {
+          $matches = [];
+          preg_match('/([-a-z_A-Z0-9]*).html/', $file, $matches);
+          $data['inputType'][$matches[1]] = $matches[1];
+        }
       }
     }
 
@@ -141,14 +148,6 @@ class CRM_AfformAdmin_Utils {
       }
     }
 
-    // Scan for input types
-    // FIXME: Need a way to load this from other extensions too
-    foreach (glob(__DIR__ . '/ang/afGuiEditor/inputType/*.html') as $file) {
-      $matches = [];
-      preg_match('/([-a-z_A-Z0-9]*).html/', $file, $matches);
-      $data['inputType'][$matches[1]] = $matches[1];
-    }
-
     $data['styles'] = [
       'default' => E::ts('Default'),
       'primary' => E::ts('Primary'),