Skip to content
Snippets Groups Projects
Commit c7cb7068 authored by David Valdez's avatar David Valdez Committed by Lucas Hedding
Browse files

Issue #2933306 by gnuget, jian he, heddn: EntityLookup fatal error on config entity type

parent e0e50113
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\migrate_plus\Plugin\migrate\process; namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface; use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
...@@ -275,7 +276,8 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn ...@@ -275,7 +276,8 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
if (!$ignoreCase) { if (!$ignoreCase) {
// Returns the entity's identifier. // Returns the entity's identifier.
foreach ($results as $k => $identifier) { foreach ($results as $k => $identifier) {
$result_value = $this->entityManager->getStorage($this->lookupEntityType)->load($identifier)->{$this->lookupValueKey}->value; $entity = $this->entityManager->getStorage($this->lookupEntityType)->load($identifier);
$result_value = $entity instanceof ConfigEntityInterface ? $entity->get($this->lookupValueKey) : $entity->get($this->lookupValueKey)->value;
if (($multiple && !in_array($result_value, $value, TRUE)) || (!$multiple && $result_value !== $value)) { if (($multiple && !in_array($result_value, $value, TRUE)) || (!$multiple && $result_value !== $value)) {
unset($results[$k]); unset($results[$k]);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
...@@ -183,7 +184,9 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa ...@@ -183,7 +184,9 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
} }
} }
elseif ($entity->{$property}->getValue()) { elseif ($entity->{$property}->getValue()) {
$this->assertEquals($expectedValue, $entity->{$property}[0]->entity->$key->value); $referenced_entity = $entity->{$property}[0]->entity;
$result_value = $referenced_entity instanceof ConfigEntityInterface ? $referenced_entity->get($key) : $referenced_entity->get($key)->value;
$this->assertEquals($expectedValue, $result_value);
} }
else { else {
$this->fail("Expected value: $expectedValue does not exist in $property."); $this->fail("Expected value: $expectedValue does not exist in $property.");
...@@ -708,6 +711,53 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa ...@@ -708,6 +711,53 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
], ],
], ],
], ],
'lookup config entity' => [
'definition' => [
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
[
'id' => 1,
'name' => 'user 1',
'mail' => 'user1@user1.com',
'roles' => ['role_1'],
],
],
'ids' => [
'id' => ['type' => 'integer'],
],
],
'process' => [
'id' => 'id',
'name' => 'name',
'roles' => [
'plugin' => 'entity_lookup',
'entity_type' => 'user_role',
'value_key' => 'id',
'source' => 'roles',
],
],
'destination' => [
'plugin' => 'entity:user',
],
],
'expected' => [
'row 1' => [
'id' => 1,
'name' => 'user 1',
'roles' => [
'id' => 'role_1',
'label' => 'Role 1',
],
],
],
'pre seed' => [
'user_role' => [
'id' => 'role_1',
'label' => 'Role 1',
],
],
],
]; ];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment