Skip to content

Commit 8f2010b

Browse files
authored
Merge pull request jhedstrom#241 from kerasai/entityref-by-id
Allow Entity Reference Field Handler to Refernce by ID
2 parents 5e23dcd + 4b2337c commit 8f2010b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public function expand($values) {
1515
$entity_type_id = $this->fieldInfo->getSetting('target_type');
1616
$entity_definition = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
1717

18+
$id_key = $entity_definition->getKey('id');
19+
1820
// Determine label field key.
1921
if ($entity_type_id !== 'user') {
2022
$label_key = $entity_definition->getKey('label');
@@ -35,7 +37,11 @@ public function expand($values) {
3537
}
3638

3739
foreach ((array) $values as $value) {
38-
$query = \Drupal::entityQuery($entity_type_id)->condition($label_key, $value);
40+
$query = \Drupal::entityQuery($entity_type_id);
41+
$or = $query->orConditionGroup();
42+
$or->condition($id_key, $value)
43+
->condition($label_key, $value);
44+
$query->condition($or);
3945
$query->accessCheck(FALSE);
4046
if ($target_bundles && $target_bundle_key) {
4147
$query->condition($target_bundle_key, $target_bundles, 'IN');

0 commit comments

Comments
 (0)