For any entity getting label using entity_metadata_wrapper is recommended. Additionally, it will help in adding additional support for translations.

Comments

purushotam.rai created an issue. See original summary.

purushotam.rai’s picture

purushotam.rai’s picture

Status: Active » Needs review

Status: Needs review » Needs work
purushotam.rai’s picture

updated entity_autocomplete_element_label function as well.

b-prod’s picture

Status: Needs work » Closed (works as designed)

@purushotam.rai
This module does not depend on Entity API (@see http://cgit.drupalcode.org/entity_autocomplete/tree/entity_autocomplete....).
So we can not rely on the entity_metadata_wrapper() function, which may not exist if the Entity API module is not installed.

Moreover, you should factorise your code inside a new function, instead of duplicating twice the same code.

Finally, there is no need to load the entity if you intend to use the entity_metadata_wrapper(), as this function will also accept an entity ID as data:
$wrapper = entity_metadata_wrapper($entity_type, $entity_id);

You can then check for the entity existence using the value() method that will return either the entity instance or NULL.

To be able to handle properly the label translation, you have to keep in mind that Drupal 7 provides 2 types of entity translations: Entity translation and i18n translations. Both does not work the same way and require very different SQL queries.
This really needs to be handle using a single query and not extra processes that will have a bad result on performances...