function crm_core_relationship_ui_add_relationship_autocomplete in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship_autocomplete()
- 8.2 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship_autocomplete()
- 7 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship_autocomplete()
Autocomplete function for add relationship form. Lookup for contacts.
Parameters
$crm_core_contact: Entity object of crm_core_contact type.
$relationship_type: Relation type object.
$reverse: Whether relation is reversed.
$string: String CRM contact is started with.
1 string reference to 'crm_core_relationship_ui_add_relationship_autocomplete'
- crm_core_relationship_ui_menu in modules/
crm_core_relationship_ui/ crm_core_relationship_ui.module - Implements hook_menu().
File
- modules/
crm_core_relationship_ui/ crm_core_relationship_ui.pages.inc, line 384 - CRM Core Relationship UI Pages.
Code
function crm_core_relationship_ui_add_relationship_autocomplete($crm_core_contact, $relationship_type, $reverse, $string) {
module_load_include('inc', 'crm_core_relationship_ui');
$matches = [];
$contact_types = array_keys(crm_core_relationship_load_contact_types($relationship_type, $reverse));
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'crm_core_contact')
->propertyCondition('type', $contact_types, 'IN')
->range(0, 20);
if ($crm_core_contact != NULL) {
$query
->propertyCondition('contact_id', $crm_core_contact->contact_id, '<>');
}
$query
->addMetaData('match', $string)
->addTag(variable_get('crm_core_contact_search_query_tag', 'crm_core_contact_search'));
$result = $query
->execute();
$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 . " [cid:{$contact->contact_id}]"] = $crm_core_contact_title;
}
// Return for JS.
drupal_json_output($matches);
}