Loading src/Plugin/migrate/process/EntityLookup.php +3 −2 Changes for src/Plugin/migrate/process/EntityLookup.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -37,7 +37,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * values. Defaults to '=' for scalar values and 'IN' for arrays. * - bundle_key: (optional) The name of the bundle field on the entity type * being queried. * - bundle: (optional) The value to query for the bundle. * - bundle: (optional) The value to query for the bundle - can be a string or * an array. * - access_check: (optional) Indicates if access to the entity for this user * will be checked. Default is true. * - ignore_case: (optional) Whether to ignore case in the query. Defaults to Loading Loading @@ -250,7 +251,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn } if ($this->lookupBundleKey) { $query->condition($this->lookupBundleKey, $this->lookupBundle); $query->condition($this->lookupBundleKey, (array) $this->lookupBundle, 'IN'); } $results = $query->execute(); Loading tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php +41 −0 Changes for tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php: 41 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -187,4 +187,45 @@ final class EntityLookupTest extends KernelTestBase { ]; } /** * Tests a lookup with bundle conditions. */ public function testEntityLookupWithBundles(): void { $migration = \Drupal::service('plugin.manager.migration') ->createStubMigration([ 'id' => 'test', 'source' => [], 'process' => [], 'destination' => [ 'plugin' => 'entity:node', ], ]); // Create a node of article content type. $this->createNode([ 'title' => 'article 1', 'type' => 'article', ]); $configuration = [ 'entity_type' => 'node', 'value_key' => 'title', 'bundle_key' => 'type', 'bundle' => 'page', ]; // The search is performed by one bundle - node is not found. $plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_lookup', $configuration, $migration); $value = $plugin->transform('article 1', $this->migrateExecutable, new Row(), 'destination_property'); $this->assertEquals(NULL, $value); // Now include both bundles in the search - node is found. $configuration['bundle'] = ['page', 'article']; $plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_lookup', $configuration, $migration); $value = $plugin->transform('article 1', $this->migrateExecutable, new Row(), 'destination_property'); $this->assertEquals('4', $value); } } Loading
src/Plugin/migrate/process/EntityLookup.php +3 −2 Changes for src/Plugin/migrate/process/EntityLookup.php: 3 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -37,7 +37,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * values. Defaults to '=' for scalar values and 'IN' for arrays. * - bundle_key: (optional) The name of the bundle field on the entity type * being queried. * - bundle: (optional) The value to query for the bundle. * - bundle: (optional) The value to query for the bundle - can be a string or * an array. * - access_check: (optional) Indicates if access to the entity for this user * will be checked. Default is true. * - ignore_case: (optional) Whether to ignore case in the query. Defaults to Loading Loading @@ -250,7 +251,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn } if ($this->lookupBundleKey) { $query->condition($this->lookupBundleKey, $this->lookupBundle); $query->condition($this->lookupBundleKey, (array) $this->lookupBundle, 'IN'); } $results = $query->execute(); Loading
tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php +41 −0 Changes for tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php: 41 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -187,4 +187,45 @@ final class EntityLookupTest extends KernelTestBase { ]; } /** * Tests a lookup with bundle conditions. */ public function testEntityLookupWithBundles(): void { $migration = \Drupal::service('plugin.manager.migration') ->createStubMigration([ 'id' => 'test', 'source' => [], 'process' => [], 'destination' => [ 'plugin' => 'entity:node', ], ]); // Create a node of article content type. $this->createNode([ 'title' => 'article 1', 'type' => 'article', ]); $configuration = [ 'entity_type' => 'node', 'value_key' => 'title', 'bundle_key' => 'type', 'bundle' => 'page', ]; // The search is performed by one bundle - node is not found. $plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_lookup', $configuration, $migration); $value = $plugin->transform('article 1', $this->migrateExecutable, new Row(), 'destination_property'); $this->assertEquals(NULL, $value); // Now include both bundles in the search - node is found. $configuration['bundle'] = ['page', 'article']; $plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_lookup', $configuration, $migration); $value = $plugin->transform('article 1', $this->migrateExecutable, new Row(), 'destination_property'); $this->assertEquals('4', $value); } }