From d575c179d81760e260ce91fa7afff7dea4585914 Mon Sep 17 00:00:00 2001 From: Andrei Mondoc Date: Sat, 16 Sep 2017 05:21:22 +0100 Subject: [PATCH] fix get_civi_contact() method #54 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contact API seems to fail when passing ‘return’ with an empty value. Seems to affect CiviCRM 4.7.24 --- .../class-civicrm-caldera-forms-helper.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/includes/class-civicrm-caldera-forms-helper.php b/includes/class-civicrm-caldera-forms-helper.php index 44fd668..b2d0ca6 100644 --- a/includes/class-civicrm-caldera-forms-helper.php +++ b/includes/class-civicrm-caldera-forms-helper.php @@ -169,24 +169,20 @@ public static function get_civi_contact( $cid ) { if ( $cid != 0 ) { - $fields = civicrm_api3( 'Contact', 'getsingle', array( + $params = array( 'sequential' => 1, 'id' => $cid, - )); + ); + + $fields = civicrm_api3( 'Contact', 'getsingle', $params ); // Custom fields - $c_fields = CiviCRM_Caldera_Forms_Helper::get_contact_custom_fields(); + $c_fields = implode( ',', CiviCRM_Caldera_Forms_Helper::get_contact_custom_fields() ); - $c_fields_string = ''; - foreach ( $c_fields as $key => $value ) { - $c_fields_string .= $key . ','; - } + if ( empty( $c_fields ) ) return $fields; - $custom_fields = civicrm_api3( 'Contact', 'getsingle', array( - 'sequential' => 1, - 'id' => $cid, - 'return' => $c_fields_string, - )); + $params['return'] = $c_fields; + $custom_fields = civicrm_api3( 'Contact', 'getsingle', $params ); return array_merge( $fields, $custom_fields );