for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Drupal\Driver\Fields\Drupal7;
/**
* Entityreference field handler for Drupal 7.
*/
class EntityreferenceHandler extends AbstractHandler {
* {@inheritdoc}
public function expand($values) {
$entity_type = $this->fieldInfo['settings']['target_type'];
$entity_info = entity_get_info($entity_type);
// For users set label to username.
if ($entity_type == 'user') {
$entity_info['entity keys']['label'] = 'name';
}
$return = [];
foreach ($values as $value) {
$target_id = db_select($entity_info['base table'], 't')
->fields('t', [$entity_info['entity keys']['id']])
->condition('t.' . $entity_info['entity keys']['label'], $value)
->execute()->fetchField();
if ($target_id) {
$return[$this->language][] = ['target_id' => $target_id];
return $return;