- Issue created by @dshumaker
- Status changed to Needs review
over 1 year ago 9:54pm 5 June 2023 - πΊπΈUnited States danflanagan8 St. Louis, US
Hi @dshumaker!
This is an interesting case! I'm going to think "out load" here so it's clear to you whether I'm understanding the problem correctly.
Let's forget about the possibility of an X just to start simple. We would have this:
field_pct_match: plugin: entity_lookup entity_type: node negate: true bundle: pct_ceilingproduct source: 'PCT Match' value_key: title
Is that right?
But we want to skip the row if that lookup is null unless 'Company' is 'X'. So let's add that logic as a second operation in the pipeline.
field_pct_match: - plugin: entity_lookup entity_type: node negate: true bundle: pct_ceilingproduct source: 'PCT Match' value_key: title - plugin: skip_on_condition method: row message: 'Non-X products must have a valid pct_match %s %s' message_context: - 'PCT Match' - 'Item Number' condition: plugin: and conditions: - plugin: is_null // This condition is using the same source and the skip_on_condition plugin, which is the entity_lookup value in the process pipeline - plugin: not:equals value: 'X' source: Company // This condition is using a different source that we specify
That's untested, but I think it should work, assuming I understand the problem correctly.
Hopefully that helps. I always like seeing the interesting ways people use this module. It gives me ideas for ways to make it better. I especially like seeing your use of
message_context
, which I was really excited to add but haven't had a chance to use in the real world.Cheers!
- πΊπΈUnited States dshumaker
Hi @danflanagan8 , I was pressed for time and so extended the php class to get it working. When I have a little more time I can work with you to try out some more tests.
But here are the gist of the changes I made to the EntityLookup process plugin to satisfy my requirements:
/** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { // If the source data is an empty array, return the same. - if (gettype($value) === 'array' && count($value) === 0) { + if (gettype($value) === 'array' && count($value) === 0 || ($row->get('Company') == "XX")) { return []; }
and
@@ -256,7 +86,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn $results = $query->execute(); if (empty($results)) { - return NULL; + throw new MigrateException('PCT Match field is null or invalid and is required.'); }
hopefully helpful! :)