3 namespace Drupal\Driver\Fields\Drupal7;
6 * Entityreference field handler for Drupal 7.
8 class EntityreferenceHandler extends AbstractHandler {
13 public function expand($values) {
14 $entity_type = $this->fieldInfo['settings']['target_type'];
15 $entity_info = entity_get_info($entity_type);
16 // For users set label to username.
17 if ($entity_type == 'user') {
18 $entity_info['entity keys']['label'] = 'name';
22 foreach ($values as $value) {
23 $target_id = db_select($entity_info['base table'], 't')
24 ->fields('t', array($entity_info['entity keys']['id']))
25 ->condition('t.' . $entity_info['entity keys']['label'], $value)
26 ->execute()->fetchField();
28 $return[$this->language][] = array('target_id' => $target_id);