Problem/Motivation
It is currently not possible to iterate over a simple array of values. The 'sub_process' plugin only handles nested arrays where you can define a separate process pipeline for each sub-key. It is not currently possible to simply define a process pipeline and have that execute for each value in a list of values.
Note that despite the similar title this is not related to #2889717: Iterate through rows as far as I can tell.
Steps to reproduce
-
Proposed resolution
Add an 'iterate' process plugin.
Remaining tasks
- Agree that this is useful
- Write tests
User interface changes
-
API changes
A new 'iterate' process plugin.
Data model changes
-
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3278748-2.patch | 4.81 KB | tstoeckler |
Comments
Comment #2
tstoecklerHere we go. Had this locally for a project but ended up not needing this for various reasons and did not want to lose the effort. Did verify that it works and did go ahead and write some proper docs so to check off one requirement to get this in, unfortunately I did not - and probably will not - have the time to write some tests for this.
Comment #3
danflanagan8This is pretty interesting to me. I'm interested in seeing better examples though. The first example:
As far as I can tell, this is identical to the simpler:
since
format_datedoes not "handle_multiples".The example using
extractis more interesting becauseextractdoes "handle_multiples". Still, I think that gets us the same thing as this:I think more compelling examples would be good. This plugin strikes me as something I would potentially reach for, but I don't think I'd use it for either of these cases.
Comment #4
danflanagan8I just put in a new issue with an alternative approach that manages to pass the complexity onto sub_process. #3314502: Add wrapper process plugin to wrap/unwrap values in arrays
Comment #5
luksakThis works like a charm! Thank you!
I think that for the specific use case of having an array with values this is the simpler and better solution than the approach of #3314502: Add wrapper process plugin to wrap/unwrap values in arrays.
Comment #6
luksakSorry, probably that needs a better review ;)
Comment #7
benjifisherI think you can get the same effect using the
build_arrayprocess plugin from #3440904: Process plugin: build an array from source, destination, pipeline.Instead of this example from the doc block for
iterateyou can use
build_arrayto prepare the array of arrays thatsub_processexpects:As @danflanagan8 pointed out in #3, it is much simpler in this case to let the Migrate API loop through the array for you, but I think this example shows that any time you want to use
iterate, you can get the same effect withbuild_arrayandsub_process.Many simple uses of
sub_processcan also be handled bybuild_array. The second example from #3 becomesThe
build_arrayplugin usesarray_walk_recursive(), which is a lot simpler thansub_processanditerate, both of which create a separate process pipeline. So I prefer to usebuild_arraywhen it can replace one of the others.Comment #8
heddnI'll take comment #7 as a good way to keep things a bit more DRY. If you still feel strongly about the addition of this feature, feel free to re-open and propose some alternatives.