From: Coleman Watts Date: Wed, 30 Jun 2021 20:50:45 +0000 (-0400) Subject: Ensure APIv3 EntityRef fields always return the value of the `id_field`. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e13640cc80fbeeb4b9a6724e8a638bb1c70d1f53;p=civicrm-core.git Ensure APIv3 EntityRef fields always return the value of the `id_field`. 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. --- diff --git a/api/v3/Activity.php b/api/v3/Activity.php index 422ebff590..d6dc51b7ff 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -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'; diff --git a/api/v3/Campaign.php b/api/v3/Campaign.php index 3ea11481d9..3a39dd3bc0 100644 --- a/api/v3/Campaign.php +++ b/api/v3/Campaign.php @@ -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'; diff --git a/api/v3/Event.php b/api/v3/Event.php index 324bb9775b..f20d6702cf 100644 --- a/api/v3/Event.php +++ b/api/v3/Event.php @@ -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'])) { diff --git a/api/v3/MembershipType.php b/api/v3/MembershipType.php index 9dd682e0a9..595b18046a 100644 --- a/api/v3/MembershipType.php +++ b/api/v3/MembershipType.php @@ -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; } diff --git a/ext/afform/core/api/v3/Afform.php b/ext/afform/core/api/v3/Afform.php index 41c20c63a4..fda6038cb5 100644 --- a/ext/afform/core/api/v3/Afform.php +++ b/ext/afform/core/api/v3/Afform.php @@ -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'])); }