Scan core as well as extensions for api4 entities & services
authorColeman Watts <coleman@civicrm.org>
Sun, 15 Sep 2019 14:51:54 +0000 (10:51 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 17 Sep 2019 03:11:24 +0000 (23:11 -0400)
CRM/Api4/Services.php
Civi/Api4/Action/Entity/Get.php

index ddd889a39070e1a082fa93e715eb0aa3ba34241b..0e78e1a931ae0678e023e5977c9e4087a8072f49 100644 (file)
@@ -57,8 +57,11 @@ class CRM_Api4_Services {
    */
   public static function loadServices($namespace, $tag, $container) {
     $namespace = \CRM_Utils_File::addTrailingSlash($namespace, '\\');
-    foreach (\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles() as $ext) {
-      $path = \CRM_Utils_File::addTrailingSlash(dirname($ext['filePath'])) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
+    $locations = array_merge([\Civi::paths()->getPath('[civicrm.root]/.')],
+      array_column(\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'filePath')
+    );
+    foreach ($locations as $location) {
+      $path = \CRM_Utils_File::addTrailingSlash(dirname($location)) . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
       foreach (glob("$path*.php") as $file) {
         $matches = [];
         preg_match('/(\w*).php/', $file, $matches);
index 1d4678cd3c05191853f62650fdbd1dd82ce78edf..4f75909524971e11d8ecb4d81ee9a8fb317046eb 100644 (file)
@@ -25,8 +25,11 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
    */
   protected function getRecords() {
     $entities = [];
-    foreach (\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles() as $ext) {
-      $dir = \CRM_Utils_File::addTrailingSlash(dirname($ext['filePath'])) . 'Civi/Api4';
+    $locations = array_merge([\Civi::paths()->getPath('[civicrm.root]/.')],
+      array_column(\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'filePath')
+    );
+    foreach ($locations as $location) {
+      $dir = \CRM_Utils_File::addTrailingSlash(dirname($location)) . 'Civi/Api4';
       if (is_dir($dir)) {
         foreach (glob("$dir/*.php") as $file) {
           $matches = [];