function wf_crm_get_custom in Webform CiviCRM Integration 7.3
Get custom data for an entity
Parameters
$entity_id: Numeric id of entity
$entity_type: Type of crm entity. 'contact' is assumed
$normalize: Default true: if true shift all arrays to start at index 1
Return value
array
3 calls to wf_crm_get_custom()
- wf_crm_contact_get in ./
webform_civicrm_forms.inc - Fetch all relevant data for a given contact Used to load contacts for pre-filling a webform, and also to fill in a contact via ajax
- wf_crm_save_custom in ./
webform_civicrm_utils.inc - Save custom data for an entity
- _wf_crm_frontend_form_alter in ./
webform_civicrm_forms.inc - Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.
File
- ./
webform_civicrm_utils.inc, line 370 - Webform CiviCRM module's common utility functions.
Code
function wf_crm_get_custom($entity_id, $entity_type = NULL, $normalize = TRUE) {
static $parents = array();
if (empty($parents)) {
require_once 'CRM/Core/BAO/CustomValueTable.php';
// Create matching table to sort fields by group
foreach (wf_crm_get_fields() as $key => $value) {
list($group, $field) = explode('_', $key, 2);
if (substr($field, 0, 7) == 'custom_') {
$parents[$field] = $group;
}
}
}
$params = array(
'entityID' => $entity_id,
);
if ($entity_type) {
$params['entityType'] = ucfirst($entity_type);
}
$result = CRM_Core_BAO_CustomValueTable::getValues($params);
if (!empty($result['is_error'])) {
return array();
}
unset($result['is_error'], $result['entityID']);
$values = array();
// Convert multi-value strings to arrays and sort by group
foreach ($result as $key => $value) {
$pieces = explode('_', $key);
if ($pieces[0] == 'custom') {
$name = 'custom_' . $pieces[1];
if (empty($pieces[2])) {
$pieces[2] = $normalize ? 1 : 0;
}
if (isset($parents[$name])) {
$values[$parents[$name]][$pieces[2]][$name] = $value;
}
}
}
if ($normalize) {
// Normalize array keys
foreach ($values as &$value) {
array_unshift($value, 0);
unset($value[0]);
}
}
return $values;
}