You are here

function crm_core_user_sync_contact_autocomplete in CRM Core 8.2

Same name and namespace in other branches
  1. 7 modules/crm_core_user_sync/crm_core_user_sync.admin.inc \crm_core_user_sync_contact_autocomplete()

User autocomplete for user->contact relation form.

1 string reference to 'crm_core_user_sync_contact_autocomplete'
crm_core_user_sync_menu in modules/crm_core_user_sync/crm_core_user_sync.module
Implements hook_menu()

File

modules/crm_core_user_sync/crm_core_user_sync.admin.inc, line 488

Code

function crm_core_user_sync_contact_autocomplete($search_string) {
  $matches = array();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'crm_core_contact')
    ->range(0, 20);
  $query
    ->addMetaData('match', $search_string)
    ->addTag(variable_get('crm_core_contact_search_query_tag', 'crm_core_contact_search'));
  $query
    ->addMetaData('user', FALSE);
  $result = $query
    ->execute();
  if (!empty($result)) {
    $contacts = entity_load('crm_core_contact', array_keys($result['crm_core_contact']));
    foreach ($contacts as $contact) {
      $crm_core_contact_title = $contact
        ->label();
      $matches[$crm_core_contact_title . " [contact_id:{$contact->contact_id}]"] = $crm_core_contact_title;
    }
  }
  drupal_json_output($matches);
}