I'm working on a migration of Album nodes, and before importing a given row, I'd like to do an entity_lookup
that checks if there exists an Album node that has both a matching title
and artist (field_artists
), skipping the row if there is a match.
My understanding is that I'll need a custom process plugin to handle that, but I can't wrap my head around how to write it so that it does the multiple entity_lookup
s properly.
This is the initial YAML from when I was only doing an entity_lookup
against the title (which works, but isn't sufficient, given that two albums by different artists could very well have the same title):
process:
skip:
-
plugin: entity_lookup
entity_type: node
bundle: album
bundle_key: type
value_key: title
source: name
ignore_case: 1
access_check: 0
Here's my YAML in its current state, in which I'm not sure how best to structure sources
:
process:
skip:
-
plugin: entity_lookup_multiple
entity_type: node
bundle: album
bundle_key: type
value_key: title
sources:
name:
value: title
field_artists:
value: field_artist
ignore_case: 1
access_check: 0
method: row
message: 'Album already exists; skipping row.'
[...etc.]
The plugin, EntityLookupMultiple.php
, is where I get lost: I'm not sure whether to extend ProcessPluginBase
like it appears other migrations do, or if I need to extend EntityLookup
directly.
class EntityLookupMultiple extends ProcessPluginBase { ... }
Then within that, I see that I think I can dig into my sources
array using $this->configuration['sources']
, and I see that I should throw a MigrateSkipRowException
if both lookups match. In between that, how do I perform an entity_lookup
against both values specified in the row (title and artist) and see if there's a matching entity that satisfies both requirements?
ProcessPluginBase
and then use entityQuery to do the lookup/check.