From aea1ae8e8d538c5698de6987c63efc36c0c1c8c9 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Wed, 11 Jan 2017 13:55:42 +1100 Subject: [PATCH] CRM-19535 - Conditionally add is_active param to entityRef Backport of #9291 by colemanw --- api/v3/Event.php | 10 ++++++---- api/v3/MembershipType.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/api/v3/Event.php b/api/v3/Event.php index 4728270b45..0c4bc4b075 100644 --- a/api/v3/Event.php +++ b/api/v3/Event.php @@ -222,10 +222,12 @@ function _civicrm_api3_event_getlist_params(&$request) { $fieldsToReturn = array('start_date', 'event_type_id', 'title', 'summary'); $request['params']['return'] = array_unique(array_merge($fieldsToReturn, $request['extra'])); $request['params']['options']['sort'] = 'start_date DESC'; - $request['params'] += array( - 'is_template' => 0, - 'is_active' => 1, - ); + if (empty($request['params']['id'])) { + $request['params'] += array( + 'is_template' => 0, + 'is_active' => 1, + ); + } } /** diff --git a/api/v3/MembershipType.php b/api/v3/MembershipType.php index 9317407206..f4820ed080 100644 --- a/api/v3/MembershipType.php +++ b/api/v3/MembershipType.php @@ -94,6 +94,25 @@ function civicrm_api3_membership_type_get($params) { return $results; } +/** + * Adjust input for getlist action. + * + * We want to only return active membership types for getlist. It's a bit + * arguable whether this should be applied at the 'get' level but, since it's hard + * to unset we'll just do it here. + * + * The usage of getlist is entity-reference fields & the like + * so using only active ones makes sense. + * + * @param array $request + * Array of parameters determined by getfields. + */ +function _civicrm_api3_membership_type_getlist_params(&$request) { + if (!isset($request['params']['is_active']) && empty($request['params']['id'])) { + $request['params']['is_active'] = 1; + } +} + /** * Deletes an existing membership type. * -- 2.25.1