Conditions | 5 |
Paths | 10 |
Total Lines | 25 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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'; |
||
19 | } |
||
20 | |||
21 | $return = array(); |
||
22 | foreach ($values as $value) { |
||
23 | $query = db_select($entity_info['base table'], 't') |
||
24 | ->fields('t', array($entity_info['entity keys']['id'])); |
||
25 | if (is_numeric($value)) { |
||
26 | $query->condition('t.' . $entity_info['entity keys']['id'], $value); |
||
27 | } |
||
28 | else { |
||
29 | $query->condition('t.' . $entity_info['entity keys']['label'], $value); |
||
30 | } |
||
31 | $target_id = $query->execute()->fetchField(); |
||
32 | if ($target_id) { |
||
33 | $return[$this->language][] = array('target_id' => $target_id); |
||
34 | } |
||
35 | } |
||
36 | return $return; |
||
37 | } |
||
38 | |||
40 |