You are here

function webform_civicrm_webform_autocomplete_options_alter in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 8.5 webform_civicrm.module \webform_civicrm_webform_autocomplete_options_alter()
  2. 7.5 webform_civicrm.module \webform_civicrm_webform_autocomplete_options_alter()

Implements hook_webform_autocomplete_options()

Invoked in webform_autocomplete module. This appends options to civicrm custom fields rendered as autocomplete.

Parameters

array $results:

object $node:

int $cid component id:

string $str:

File

./webform_civicrm.module, line 111
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_webform_autocomplete_options_alter(&$results, $node, $cid, $str) {
  module_load_include('inc', 'webform_civicrm', 'includes/wf_crm_webform_ajax');
  if (wf_crm_webform_ajax::autocompleteAccess($node, $cid)) {
    $key = wf_crm_explode_key($node->webform['components'][$cid]['form_key']);
  }
  if (isset($key) && substr($key[5], 0, 7) == 'custom_') {
    civicrm_initialize();
    $customField = wf_civicrm_api('CustomField', 'getsingle', array(
      'id' => substr($key[5], 7),
      'return' => 'option_group_id',
    ));
    if (!empty($customField['option_group_id'])) {
      $options = wf_crm_apivalues('OptionValue', 'get', array(
        'label' => array(
          'LIKE' => "%{$str}%",
        ),
        'option_group_id' => $customField['option_group_id'],
        'limit' => $node->webform['components'][$cid]['extra']['autocomplete_result_count'],
      ), 'label');
      $results = array_combine($options, $options);
    }
  }
}