function wf_crm_fill_contact_value in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 7.3 contact_component.inc \wf_crm_fill_contact_value()
- 7.4 includes/contact_component.inc \wf_crm_fill_contact_value()
Lookup contact name from ID, verify permissions, and attach as html data.
Used when rendering or altering a CiviCRM contact field.
Also sets options for select lists.
Parameters
stdClass $node: Node object
array $component: Webform component
array $element: FAPI form element (reference)
array $ids: Known entity ids
2 calls to wf_crm_fill_contact_value()
- wf_crm_webform_preprocess::fillForm in includes/
wf_crm_webform_preprocess.inc - Recursively walk through form array and set properties of CiviCRM fields
- _webform_render_civicrm_contact in includes/
contact_component.inc - Implements _webform_render_component().
File
- includes/
contact_component.inc, line 549
Code
function wf_crm_fill_contact_value($node, $component, &$element, $ids = NULL) {
$cid = wf_crm_aval($element, '#default_value', '');
if ($element['#type'] == 'hidden') {
if (!$component['extra']['show_hidden_contact']) {
return;
}
}
if ($cid) {
// Don't lookup same contact again
if (wf_crm_aval($element, '#attributes:data-civicrm-id') != $cid) {
$filters = wf_crm_search_filters($node, $component);
$name = wf_crm_contact_access($component, $filters, $cid);
if ($name !== FALSE) {
$element['#attributes']['data-civicrm-name'] = $name;
$element['#attributes']['data-civicrm-id'] = $cid;
}
else {
unset($cid);
}
}
}
if (empty($cid) && $element['#type'] == 'hidden' && $component['extra']['none_prompt']) {
$element['#attributes']['data-civicrm-name'] = filter_xss($component['extra']['none_prompt']);
}
// Set options list for select elements. We do this here so we have access to entity ids.
if (is_array($ids) && $element['#type'] == 'select') {
$filters = wf_crm_search_filters($node, $component);
$element['#options'] = wf_crm_contact_search($node, $component, $filters, wf_crm_aval($ids, 'contact', []));
// Display empty option unless there are no results
if (!$component['extra']['allow_create'] || count($element['#options']) > 1) {
$element['#empty_option'] = filter_xss($component['extra'][$element['#options'] ? 'search_prompt' : 'none_prompt']);
}
}
}