Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently there is no chance to work with the currently processed/parsed URL from outside of the data parser plugin. This could be really useful if you'd like to use this value as source (e.g. the current filename as source ID, or the data files path for migrating files besides it).
Proposed resolution
- Create a getter method for data parser plugins returning the currently processed/parsed URL
Remaining tasks
- Create a patch
User interface changes
n/a
API changes
- New getter method in
DataParserPluginInterface
Data model changes
n/a
Release notes snippet
Allow currently processed/parsed URL to be read from outside of data parser plugin
Comment | File | Size | Author |
---|
Issue fork migrate_plus-3050274
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hctomHere is the proposed patch introducing the new setter method
Comment #3
hctomMinor changes to issue title and body
Comment #4
hctomHere is an improved patch that also gets the URL for the first item.
Comment #5
heddnCan we get some tests of this?
Comment #6
hctomHere is a slightly updated patch that fixes
Only variables should be passed by reference
warnings due to thearray_shift(array_keys($this->urls))
part.Tests will be added soon (if I can get them to run, hehe).
Comment #7
hctom...and here comes a new patch with a current URL test added to the
simple_xml
parser kernel test. I chose this one, because it has a better setup compared tojson
parser kernel test and allows reusing its basic configuration.Comment #8
hctomRemoving the "Needs tests" tag, as there is a test contained in the last submitted patch
Comment #9
roborn CreditAttribution: roborn at Frontkom commentedTested also with 8.x-5.x and it is working as expected.
Comment #10
hctomAny news on this? Would really like to see this getting into the module.
Comment #11
hctomAnybody?! ;)
Comment #12
timlie CreditAttribution: timlie commentedHi hctom, how do you actually use this?
Is it possible to get the current url as a source value in your migration?
Comment #13
hctom@timilie: Sorry for the late reply. In my case, I needed this for a custom data parser plugin that is used when reading multiple XML files from a directory. In order to e.g. be able to use the basename of the currently parsed/read file as an identifier, I needed this new functionality. In my custom data parser I do the following:
With this, I can access the basename value via
my_custom_source_prop
source property in each row.Hope this helps?
Comment #14
timlie CreditAttribution: timlie commentedHi hctom,
Clear example of how to use this.
I tested this and this does indeed work. Tested against migrate_plus:8.x-5.1
Thanks a lot!
Comment #15
hctomAny news on this or is there still something to do to get it in?! I'd appreciate your feedback
Comment #16
Chalk CreditAttribution: Chalk at DrupalSquad for Pantheon commentedPatch makes sense and works for me too. Thanks you, @hctom.
Comment #19
MatroskeenThank for you the patch and especially for the unit test and sorry it took so long to have some feedback :)
I think it looks good, apart from some minor items I mentioned in the pull request (I find it easier to comment on MRs so I opened one based on patch #7).
@hctom, hopefully, you're still interested to get it done - it looks like a nice API addition.
Thanks!
Comment #20
hctom@Matroskeen No worries, but of course I am still interested in getting this in ;) I had a quick look at your comments and I'll take some time to fix all the stuff later today. Thanks for the feedback
Comment #21
hctomSo all issues should be resolved. I guess I used the wrong buttons when commenting in the MR, but I hope you can get through my changes ;)
Comment #22
MatroskeenWe're down to one open thread: https://git.drupalcode.org/project/migrate_plus/-/merge_requests/14#note...
Can you take a look, please?
Comment #23
hctomThe last open thread should be resolved... but I don't find any button how to resolve this from my end ;) But setting this to RTBC for now.
Comment #24
MatroskeenI was wondering what are the circumstances of NULL value in
currentUrl
. It seems the only case is whenurls
array is empty, which is fine I think.I resolved the last active thread and I agree it is RTBC.
Thanks!
Comment #25
heddnThanks for your contributions.
Comment #26
heddn