function Utils::wf_civicrm_api in Webform CiviCRM Integration 8.5
Wrapper for all CiviCRM API calls For consistency, future-proofing, and error handling
Parameters
string $entity: API entity
string $operation: API operation
array $params: API params
Return value
array Result of API call
Overrides UtilsInterface::wf_civicrm_api
6 calls to Utils::wf_civicrm_api()
- Utils::wf_crm_apivalues in src/
Utils.php - Get the values from an api call
- Utils::wf_crm_display_name in src/
Utils.php - Fetch contact display name
- Utils::wf_crm_get_civi_setting in src/
Utils.php - Utils::wf_crm_get_states in src/
Utils.php - Get list of states, keyed by abbreviation rather than ID.
- Utils::wf_crm_state_abbr in src/
Utils.php - Match a state/province id to its abbr. and vice-versa
File
- src/
Utils.php, line 641 - Webform CiviCRM module's common utility functions.
Class
Namespace
Drupal\webform_civicrmCode
function wf_civicrm_api($entity, $operation, $params) {
if (!$entity) {
return [];
}
$params += [
'check_permissions' => FALSE,
];
if ($operation == 'transact') {
$utils = \Drupal::service('webform_civicrm.utils');
$result = $utils
->wf_civicrm_api3_contribution_transact($params);
}
else {
$result = civicrm_api3($entity, $operation, $params);
}
// I guess we want silent errors for getoptions b/c we check it for failure separately
if (!empty($result['is_error']) && $operation != 'getoptions') {
$bt = debug_backtrace();
$n = $bt[0]['function'] == 'wf_civicrm_api' ? 1 : 0;
$file = explode('/', $bt[$n]['file']);
if (isset($params['credit_card_number'])) {
$params['credit_card_number'] = "xxxxxxxxxxxx" . substr($params['credit_card_number'], -4);
}
\Drupal::logger('webform_civicrm')
->error('The CiviCRM "@function" API returned the error: "@msg" when called by function "@fn" on line @line of @file with parameters: "@params"', [
'@function' => $entity . ' ' . $operation,
'@msg' => $result['error_message'],
'@fn' => $bt[$n + 1]['function'],
'@line' => $bt[$n]['line'],
'@file' => array_pop($file),
'@params' => print_r($params, TRUE),
]);
}
return $result;
}