Commit c7cb7068 authored by gnuget's avatar gnuget Committed by heddn

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

parent e0e50113
......@@ -2,6 +2,7 @@
namespace Drupal\migrate_plus\Plugin\migrate\process;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -275,7 +276,8 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
if (!$ignoreCase) {
// Returns the entity's 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)) {
unset($results[$k]);
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
......@@ -183,7 +184,9 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
}
}
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 {
$this->fail("Expected value: $expectedValue does not exist in $property.");
......@@ -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',
],
],
],
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment