You are here

function entity_autocomplete_get_label in Entity Autocomplete 7

Build a label smaller than 128 chars.

4 calls to entity_autocomplete_get_label()
EntityAutocompleteWebTestCase::testAutocompleteElement in tests/entity_autocomplete.test
Tests FAPI element.
EntityAutocompleteWebTestCase::testLabelAndID in tests/entity_autocomplete.test
Tests label creation and ID extraction.
entity_autocomplete in ./entity_autocomplete.module
Autocomplete callback for all entity types.
entity_autocomplete_element_label in ./entity_autocomplete.module
Retrieve entity label from its ID.

File

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

Code

function entity_autocomplete_get_label($label, $id) {
  $label = check_plain($label);
  $ref_id = ' [id:' . $id . ']';
  $ref_id_length = strlen($ref_id);
  if (drupal_strlen($label) >= 128 - $ref_id_length) {
    $label = drupal_substr($label, 124 - $ref_id_length) . ' ...';
  }
  return strip_tags(decode_entities($label)) . $ref_id;
}