You are here

function wf_crm_fill_contact_value in Webform CiviCRM Integration 7.3

Same name and namespace in other branches
  1. 7.5 includes/contact_component.inc \wf_crm_fill_contact_value()
  2. 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

Parameters

$node: Node object

$component: Webform component

$element: FAPI form element (reference)

2 calls to wf_crm_fill_contact_value()
wf_crm_fill_form in ./webform_civicrm_forms.inc
Recursively walk through form array and set properties of CiviCRM fields Called by _wf_crm_frontend_form_alter() when webform is being viewed
_webform_render_civicrm_contact in ./contact_component.inc
Implements _webform_render_component().

File

./contact_component.inc, line 394

Code

function wf_crm_fill_contact_value($node, $component, &$element) {
  $cid = wf_crm_aval($element, '#default_value', '');
  if ($element['#type'] == 'hidden') {

    // User may not change this value for hidden fields
    $element['#value'] = $cid;
    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'] = $component['extra']['none_prompt'];
  }
}