X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FMembershipType.php;h=42d4f94001a51781d44a105c1207032ba94fcace;hb=1b1931152a86683bd792c6103f9ac8fb0c0bb3ad;hp=1de6d0985c407643a3f4826aa9516526cd557d40;hpb=7f768717e37801b57add73e3c501ef61cc60327e;p=civicrm-core.git diff --git a/api/v3/MembershipType.php b/api/v3/MembershipType.php index 1de6d0985c..42d4f94001 100644 --- a/api/v3/MembershipType.php +++ b/api/v3/MembershipType.php @@ -41,6 +41,12 @@ * API result array. */ function civicrm_api3_membership_type_create($params) { + // Workaround for fields using nonstandard serialization + foreach (array('relationship_type_id', 'relationship_direction') as $field) { + if (isset($params[$field]) && is_array($params[$field])) { + $params[$field] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params[$field]); + } + } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Membership_type'); } @@ -75,7 +81,37 @@ function _civicrm_api3_membership_type_create_spec(&$params) { * API result array. */ function civicrm_api3_membership_type_get($params) { - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + $results = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + if (!empty($results['values']) && is_array($results['values'])) { + foreach ($results['values'] as &$item) { + // Workaround for fields using nonstandard serialization + foreach (array('relationship_type_id', 'relationship_direction') as $field) { + if (isset($item[$field]) && !is_array($item[$field])) { + $item[$field] = (array) $item[$field]; + } + } + } + } + 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'])) { + $request['params']['is_active'] = 1; + } } /**