You are here

function webform_civicrm_api in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_utils.inc \webform_civicrm_api()

Wrapper for all CiviCRM API calls For consistency, future-proofing, and error handling

6 calls to webform_civicrm_api()
webform_civicrm_add_remove in ./webform_civicrm_forms.inc
Handle adding/removing multivalued data for a contact/activity/etc. Currently used only for groups and tags, but written with expansion in mind.
webform_civicrm_get_options in ./webform_civicrm_utils.inc
Get option values from various civicrm tables @Param $option_group: option group name or id @Param $param: optional extra info for the query (passing a param will bypass caching) @Return array
webform_civicrm_process_submission in ./webform_civicrm_forms.inc
Webform submission handler Create/update CiviCRM contacts and related data Called by presave, insert and update webform hooks
webform_civicrm_update_6205 in ./webform_civicrm.install
Upgrade for CiviCRM 4.1 compatibility.
webform_civicrm_user_cid in ./webform_civicrm_utils.inc
Lookup a uf ID from contact ID or vice-versa

... See full list

File

./webform_civicrm_utils.inc, line 975
Webform CiviCRM module's common utility functions. The code in this file is cross-compatible with D6/Civi3 and D7/Civi4 Drupal-version-specific functions belong in webform_civicrm_dx_functions.inc

Code

function webform_civicrm_api($entity, $operation, $params) {
  $params += array(
    'check_permissions' => FALSE,
    'version' => 3,
  );
  $result = civicrm_api($entity, $operation, $params);
  if (!empty($result['is_error'])) {
    $bt = debug_backtrace();
    watchdog('webform_civicrm', 'The CiviCRM "%function" API function returned the error: "%msg" when called by line !line of !file with the following parameters: "!params"', array(
      '%function' => $entity . ' ' . $operation,
      '%msg' => $result['error_message'],
      '!line' => $bt[0]['line'],
      '!file' => array_pop(explode('/', $bt[0]['file'])),
      '!params' => print_r($params, TRUE),
    ), WATCHDOG_ERROR);
  }
  elseif (!empty($params['options']['sort']) && !empty($result['values'])) {
    $values = array();
    foreach ($result['values'] as $val) {
      if (empty($val['is_primary'])) {
        $values[] = $val;
      }
      else {
        array_unshift($values, $val);
      }
    }
    $result['values'] = $values;
  }
  return $result;
}