Skip to content

Commit

Permalink
Merge pull request #241 from kerasai/entityref-by-id
Browse files Browse the repository at this point in the history
Allow Entity Reference Field Handler to Refernce by ID
  • Loading branch information
jhedstrom authored Feb 28, 2023
2 parents 5e23dcd + 4b2337c commit 8f2010b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function expand($values) {
$entity_type_id = $this->fieldInfo->getSetting('target_type');
$entity_definition = \Drupal::entityTypeManager()->getDefinition($entity_type_id);

$id_key = $entity_definition->getKey('id');

// Determine label field key.
if ($entity_type_id !== 'user') {
$label_key = $entity_definition->getKey('label');
Expand All @@ -35,7 +37,11 @@ public function expand($values) {
}

foreach ((array) $values as $value) {
$query = \Drupal::entityQuery($entity_type_id)->condition($label_key, $value);
$query = \Drupal::entityQuery($entity_type_id);
$or = $query->orConditionGroup();
$or->condition($id_key, $value)
->condition($label_key, $value);
$query->condition($or);
$query->accessCheck(FALSE);
if ($target_bundles && $target_bundle_key) {
$query->condition($target_bundle_key, $target_bundles, 'IN');
Expand Down

0 comments on commit 8f2010b

Please sign in to comment.