- Merge request !53Issue #2787219: Added a test coverage for bundleless entities lookup. β (Open) created by Matroskeen
- π¬π§United Kingdom 2dareis2do
I had similar problem where I wanted to reference a regular field. I was able to do with the following patch and config:
_check_migrated: - plugin: entity_lookup source: '@_processed_link' access_check: false value_key: field_web_link.uri #required bundle: feed_item #required bundle_key: field_web_link.uri #required entity_type: node #required ignore_case: true # destination_field: field_web_link - plugin: skip_on_value value: null not_equals: true method: row message: Do I really want to flood my logs?
The important field is value_key. I think bundle, bundle_key and entity_type are irrelevant but necessary for entity_lookup to function
- π¬π§United Kingdom 2dareis2do
Actually please ignore my previous comment. Turns out I had not configured the value key correctly.
Here is a working example that checks if an source or processed uri has already been imported, and if so we can choose to skip the row if the value returned !== null. NULL is returned if there is no matching field_web_link_url on a node entity_type bundle aka 'feed_item" content type.
source _check_migrated: - plugin: entity_lookup source: '@_processed_link' access_check: false value_key: field_web_link.uri #required - note use of dot notation as mentioned <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/function/QueryInterface%3A%3Acondition/11.x">here</a>. This will actually map to field_web_link_uri column on the node__field_web_link table bundle: feed_item #required - for node this is the content type bundle_key: type #required - e.g. <code>Drupal::entityTypeManager()->getStorage('node')->getEntityType()->getKey('bundle')
entity_type: node #required - entity type id
ignore_case: true
-
plugin: skip_on_value
value: null
not_equals: true
method: row
message: Row skipped because uri already exists - π©π°Denmark ressa Copenhagen
I recently tried a very minimal migration, using only
entity_generate
(Note, notentity_lookup
plugin) andsource
, which didn't work, even though all properties are labelled "optional" ...I am sharing it here, since at it says in the
entity_generate
code, that it shares properties withentity_lookup
:* All the configuration from the lookup plugin applies here. In its most
* simple form, this plugin needs no configuration. If there are fields on the
* generated entity that are required or need some value, their values can be
* provided via values and/or default_values configuration options.From https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...
From the
entity_lookup
configuration documentation:* Available configuration keys:
* - entity_type: (optional) The ID of the entity type to query for.
* - value_key: (optional) The name of the entity field on which the source
* value will be queried. If omitted, defaults to one of the following
* depending on the destination field type:
* - entity_reference: The entity label key.
* - file: The uri field.
* - image: The uri field.
* - operator: (optional) The comparison operator supported by entity query:
* See \Drupal\Core\Entity\Query\QueryInterface::condition() for available
* 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 - 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
* false, meaning the query is case-sensitive by default. Works only with
* strict operators: '=' and 'IN'.
* - destination_field: (optional) If specified, and if the plugin's source
* value is an array, the result array's items will be themselves arrays of
* the form [destination_field => ENTITY_ID].https://git.drupalcode.org/project/migrate_plus/-/blob/6.0.x/src/Plugin/...
Only after setting the values below as well, did my import not return "Failed" (and without saying why):
process: field_library: plugin: entity_lookup source: library value_key: title bundle: article entity_type: node
I updated the existing
entity_generate
doc page (it had a very basic, failing example I mentioned in the beginning) and created a new doc page forentity_lookup
, where I also included the great answers and question in comments #7 to #12, thanks @james.williams amd @tnfno!