diff --git a/src/Plugin/migrate/process/EntityLookup.php b/src/Plugin/migrate/process/EntityLookup.php index 2313d5a2e8ed6b11b703c158c95974e616579b7f..2ae0d07c1de2a438c830da55412a9c6618b2e7da 100644 --- a/src/Plugin/migrate/process/EntityLookup.php +++ b/src/Plugin/migrate/process/EntityLookup.php @@ -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]); } diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php index ad6d9894202258b683a44d602b4517b205b33a70..3d46496de479d92ba2507ca6506dcbad65733551 100644 --- a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php @@ -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', + ], + ], + ], ]; }