Gets the entity labels.
protected function getLabels(array $items) {
$entity_ids = array();
$entity_labels = array();
// Build an array of entity IDs.
foreach ($items as $item) {
$entity_ids[] = $item['target_id'];
}
// Load those entities and loop through them to extract their labels.
$entities = entity_load_multiple($this->field['settings']['target_type'], $entity_ids);
foreach ($entities as $entity_id => $entity_item) {
$label = $entity_item
->label();
$key = "{$label} ({$entity_id})";
// Labels containing commas or quotes must be wrapped in quotes.
if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
$key = '"' . str_replace('"', '""', $key) . '"';
}
$entity_labels[] = $key;
}
return $entity_labels;
}