From 70ef079f8fd56875a186aa80cd5665d8f4703369 Mon Sep 17 00:00:00 2001 From: bec <bec@81067.no-reply.drupal.org> Date: Tue, 11 Oct 2016 14:28:48 -0500 Subject: [PATCH] Issue #2782961 by becw: Allow returning multiple results from the entity_lookup process plugin --- src/Plugin/migrate/process/EntityLookup.php | 23 ++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Plugin/migrate/process/EntityLookup.php b/src/Plugin/migrate/process/EntityLookup.php index 54b2a805..abd34142 100644 --- a/src/Plugin/migrate/process/EntityLookup.php +++ b/src/Plugin/migrate/process/EntityLookup.php @@ -226,25 +226,24 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn return NULL; } - if ($multiple && !empty($this->destinationProperty)) { - array_walk($results, function (&$value) { - $value = [$this->destinationProperty => $value]; - }); - - return array_values($results); - } - // By default do a case-sensitive comparison. if (!$ignoreCase) { // Returns the entity's identifier. - foreach ($results as $identifier) { - if ($value === $this->entityManager->getStorage($this->lookupEntityType)->load($identifier)->{$this->lookupValueKey}->value) { - return $identifier; + foreach ($results as $k => $identifier) { + $result_value = $this->entityManager->getStorage($this->lookupEntityType)->load($identifier)->{$this->lookupValueKey}->value; + if (($multiple && !in_array($result_value, $value, TRUE)) || (!$multiple && $result_value !== $value)) { + unset($results[$k]); } } } - return reset($results); + if ($multiple && !empty($this->destinationProperty)) { + array_walk($results, function (&$value) { + $value = [$this->destinationProperty => $value]; + }); + } + + return $multiple ? array_values($results) : reset($results); } } -- GitLab