Skip to content
Snippets Groups Projects
Commit e13640cc authored by colemanw's avatar colemanw
Browse files

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.
parent 8c5bb56d
Branches
Tags
No related merge requests found
......@@ -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';
......
......@@ -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';
......
......@@ -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'])) {
......
......@@ -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;
}
......
......@@ -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']));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment