You are here

function redhen_relation_autocomplete in RedHen CRM 7

Autocomplete callback for listing available entities for a relation type.

1 string reference to 'redhen_relation_autocomplete'
redhen_relation_menu in modules/redhen_relation/redhen_relation.module
Implements hook_menu().

File

modules/redhen_relation/redhen_relation.module, line 660
Redhen CRM Relation Module.

Code

function redhen_relation_autocomplete($relation_type = '', $entity_type_to_relate = '', $entity_type = '', $entity_id = '', $search = '') {
  $options = array();
  if (!empty($relation_type) && !empty($entity_type_to_relate) && !empty($entity_type) && !empty($entity_id)) {
    $entity = entity_load_single($entity_type, $entity_id);
    $available_entities = redhen_relation_get_available_entities($entity, $entity_type_to_relate, $relation_type, $search, 10);
    foreach ($available_entities as $available_entity) {
      $entity_id = $available_entity
        ->internalIdentifier();
      $entity_label = $available_entity
        ->label();
      $options[check_plain($entity_label) . ' (' . $entity_id . ')'] = check_plain($entity_label);
    }
  }
  drupal_json_output($options);
}