Skip to content
Snippets Groups Projects
Commit f993931f authored by Ivan Doroshenko's avatar Ivan Doroshenko
Browse files

Issue #3253347 by Matroskeen: Allow to use several bundles in entity_lookup plugin

parent dae1881a
No related branches found
No related tags found
1 merge request!8Issue #3229479: Entity_lookup taxonomy_term restricted by VID
......@@ -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
......@@ -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();
......
......@@ -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);
}
}
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