Ensure APIv3 EntityRef fields always return the value of the `id_field`.
authorColeman Watts <coleman@civicrm.org>
Wed, 30 Jun 2021 20:50:45 +0000 (16:50 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 30 Jun 2021 20:50:45 +0000 (16:50 -0400)
Usually it's safe to assume the `id_field` === "id", which is automatically returned
by APIv3. However in the case of looking up records by name, etc. we must ensure that value
gets returned.

api/v3/Activity.php
api/v3/Campaign.php
api/v3/Event.php
api/v3/MembershipType.php
ext/afform/core/api/v3/Afform.php

index 422ebff5905d98b3345d749f4f96a67eed860c4f..d6dc51b7ffabcd6aab626668cdb9395a152c4bf2 100644 (file)
@@ -744,6 +744,8 @@ function _civicrm_api3_activity_getlist_params(&$request) {
     'activity_type_id',
     'subject',
     'source_contact_id',
+    $request['id_field'],
+    $request['label_field'],
   ];
   $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
   $request['params']['options']['sort'] = 'activity_date_time DESC';
index 3ea11481d9b8b5037b32191bde7d11de7e552c09..3a39dd3bc03a0821c387a5cc35ad3b2d770fa6c7 100644 (file)
@@ -81,7 +81,15 @@ function civicrm_api3_campaign_delete($params) {
  * @param array $request
  */
 function _civicrm_api3_campaign_getlist_params(&$request) {
-  $fieldsToReturn = ['title', 'campaign_type_id', 'status_id', 'start_date', 'end_date'];
+  $fieldsToReturn = [
+    'title',
+    'campaign_type_id',
+    'status_id',
+    'start_date',
+    'end_date',
+    $request['id_field'],
+    $request['label_field'],
+  ];
   $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
   if (empty($request['params']['id'])) {
     $request['params']['options']['sort'] = 'start_date DESC, title';
index 324bb9775b2748a7a1e5c339d3992f770787f3ac..f20d6702cf81ec2e303c415261e4a4ae73c86659 100644 (file)
@@ -204,7 +204,14 @@ function _civicrm_api3_event_getisfull(&$event, $event_id) {
  * @param array $request
  */
 function _civicrm_api3_event_getlist_params(&$request) {
-  $fieldsToReturn = ['start_date', 'event_type_id', 'title', 'summary'];
+  $fieldsToReturn = [
+    'start_date',
+    'event_type_id',
+    'title',
+    'summary',
+    $request['id_field'],
+    $request['label_field'],
+  ];
   $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
   $request['params']['options']['sort'] = 'start_date DESC';
   if (empty($request['params']['id'])) {
index 9dd682e0a9fb7026f83c8faf55b8ed8b396c6109..595b18046a230634b30ce543863bff99b8023f65 100644 (file)
@@ -106,6 +106,7 @@ function _civicrm_api3_membership_type_get_spec(&$params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_membership_type_getlist_params(&$request) {
+  _civicrm_api3_generic_getlist_params($request);
   if (!isset($request['params']['is_active']) && empty($request['params']['id'])) {
     $request['params']['is_active'] = 1;
   }
index 41c20c63a48703177bf26f001444faec0b68fb00..fda6038cb506502cd02ccb7ea772f1b0e427dbe0 100644 (file)
@@ -88,7 +88,14 @@ function _civicrm_api3_afform_get_spec(&$fields) {
  *   API request.
  */
 function _civicrm_api3_afform_getlist_params(&$request) {
-  $fieldsToReturn = ['name', 'title', 'type', 'description'];
+  $fieldsToReturn = [
+    'name',
+    'title',
+    'type',
+    'description',
+    $request['id_field'],
+    $request['label_field'],
+  ];
   $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra']));
 }