Merge pull request #19727 from totten/master-authx-rest
[civicrm-core.git] / api / v3 / Profile.php
index 59dbf268d2bbcbd21ab7359cf391c25374e990d6..a20bd48e1e813b387600d0e3ecc23c692123def9 100644 (file)
@@ -485,11 +485,11 @@ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) {
  * @param int $profileID
  * @param int $optionsBehaviour
  *   0 = don't resolve, 1 = resolve non-aggressively, 2 = resolve aggressively - ie include country & state.
- * @param $is_flush
+ * @param bool $is_flush
  *
  * @return array|void
  */
-function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = 1, $is_flush) {
+function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour, $is_flush) {
   static $profileFields = [];
   if ($is_flush) {
     $profileFields = [];
@@ -500,7 +500,7 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
   if (isset($profileFields[$profileID])) {
     return $profileFields[$profileID];
   }
-  $fields = civicrm_api3('uf_field', 'get', ['uf_group_id' => $profileID]);
+  $fields = civicrm_api3('uf_field', 'get', ['uf_group_id' => $profileID, 'options' => ['limit' => 0]]);
   $entities = [];
   foreach ($fields['values'] as $field) {
     if (!$field['is_active']) {
@@ -604,6 +604,7 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
        */
     }
   }
+  $profileFields[$profileID] = $profileFields[$profileID] ?? [];
   uasort($profileFields[$profileID], "_civicrm_api3_order_by_weight");
   return $profileFields[$profileID];
 }
@@ -615,14 +616,14 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
  * @return bool
  */
 function _civicrm_api3_order_by_weight($a, $b) {
-  return ($b['weight'] ?? 0) < ($a['weight'] ?? 0);
+  return ($b['weight'] ?? 0) < ($a['weight'] ?? 0) ? 1 : -1;
 }
 
 /**
  * Here we map the profile fields as stored in the uf_field table to their 'real entity'
  * we also return the profile fieldname
  *
- * @param $field
+ * @param array $field
  *
  * @return array
  */
@@ -715,7 +716,7 @@ function _civicrm_api3_profile_getProfileID($profileID) {
  *
  * e.g getfields response incl 'membership_type_id' - with api.aliases = 'membership_type'
  * returned array will include both as keys (with the same values)
- * @param $entity
+ * @param string $entity
  *
  * @return array
  */