You are here

function entity_autocomplete_element_label in Entity Autocomplete 7

Retrieve entity label from its ID.

1 call to entity_autocomplete_element_label()
entity_autocomplete_element_process in ./entity_autocomplete.module
Form element processing handler for the #autocomplete_path property.

File

./entity_autocomplete.module, line 198
Provides functionalities for entity fields autocompletion.

Code

function entity_autocomplete_element_label($entity_id, $entity_type) {
  $labels =& drupal_static(__FUNCTION__, array());
  if (!isset($labels[$entity_type][$entity_id])) {
    $labels[$entity_type][$entity_id] = $entity_id;
    if ($info = entity_get_info($entity_type)) {
      $table = $info['base table'];
      $query = db_select($table);
      $query
        ->addField($table, $info['entity keys']['label'], 'label');
      $query
        ->condition($info['entity keys']['id'], $entity_id);
      if ($row = $query
        ->execute()
        ->fetch()) {
        $labels[$entity_type][$entity_id] = entity_autocomplete_get_label($row->label, $entity_id);
      }
    }
  }
  return $labels[$entity_type][$entity_id];
}