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.
I created a patch for rewrite.inc that would enable the use of this plugin in "multi: loop" behavior
To do this, I've added a new token called [value]
that holds the value that was caught by the parser.
Comment | File | Size | Author |
---|---|---|---|
#24 | feeds_tamper-enable-multi-loop-for-rewrite-plugin-1461308-24.patch | 15.75 KB | firfin |
| |||
#1 | multi-loop-rewrite-1461308-1.patch | 1.1 KB | daniboy |
Comments
Comment #1
daniboy CreditAttribution: daniboy commentedAnd the patch...
Comment #2
twistor CreditAttribution: twistor commentedComment #3
manasiv CreditAttribution: manasiv as a volunteer commentedThe patch in #1 worked for me.
Use case:
I have a multi-valued field collection associated in a content type. A course has a lesson field collection.
Lesson consists of title, description, url fields. Feeds tamper was rewriting only the first lesson > url field. The other lesson urls were not being tampered/rewritten as required.
Comment #4
athanor CreditAttribution: athanor commentedThanks dude, you saved my day! Patch #1 helped me with rewrite of image uri-s mapped to multi value image field.
Comment #5
brtamas CreditAttribution: brtamas at Integral Vision Ltd commentedI have adjusted that patch for 7.1.1
Comment #6
victoriachan CreditAttribution: victoriachan at Torchbox commentedHi,
Can you please explain how to use this? I have a multiple
[first_name]
field, and a multiple[last_name]
field, and I want to import them tofield_full_name
.So in my importer, I mapped:
And then in feeds_tamper settings, I added the 'Rewrite' plugin to the last_name field with the values:
[first_name] [last_name]
. But what I got was not right:Eg. I had:
First names:
Last names:
Result:
It should be:
Am I using this wrongly?
Thanks,
Victoria
Comment #7
victoriachan CreditAttribution: victoriachan at Torchbox commentedHi,
I've recreated this patch to make it work with multiple multiple value fields like described in my comment #6 above. So, for example you can now use the rewrite tamper for multiple [first_name] field with multiple [last_name] field, and the delta will be matched.
The rewrite plugin should still work with fields that are not multi value.
Example use case:
In importer, map:
- first_name => Temporary target 1
- last_name => field_full_name
In tamper settings:
Add a 'Rewrite' Feeds Tamper plugin to 'last_name' with the value of
[first_name] [last_name]
Please review. Thanks!
Victoria
Comment #9
victoriachan CreditAttribution: victoriachan at Torchbox commentedUpdated patch for testing.
Comment #11
victoriachan CreditAttribution: victoriachan at Torchbox commentedTrying again to pass test. Sorry for spamming.
Comment #13
victoriachan CreditAttribution: victoriachan at Torchbox commentedUpdated again to pass test. Also added $delta to all 'multi => loop' plugin's callback functions though it won't be used for most of them (default to 0) so it is all standardised, and hopefully pass the tests.
Comment #15
victoriachan CreditAttribution: victoriachan at Torchbox commentedI think my patch is failing the tests because the tests are now running with Feeds 7.x-2.0-beta3 whereas the previously passed test was running Feeds 7.x-2.0-beta2. This has nothing to do with my changes.
I'm attaching a patch with just a minimal change just to run it through the automated testing.
Not sure what to do to fix it as it is very difficult to understand the tests! It is now failing on the permissions setup in FeedsTamperEfqFinderTestCase (maybe 'administer fields' needs removing on line 22?) and also failing on the expected hashes in feeds_tamper_ui.test (defined in assertHashedDevseedFeedContent()), which I suspect just needs updating the hard coded hash, though I have no idea what the hashes are of, and it's probably better not to hard code the hash.
Possibly this is a separate issue: to get current dev to pass tests with latest Feeds version.
Help!
Comment #17
Madis CreditAttribution: Madis at ADM Interactive commentedNo extensive testing, but patch in #13 solved my issue which was pretty much the same as described in #6.
I had to do a small change though since NULL values messed things up otherwise. Replaced
isset($value[$delta])
witharray_key_exists($delta, $value)
infeeds_tamper_rewrite_callback()
.Comment #18
elpino CreditAttribution: elpino as a volunteer commentedI manually applied the patch and it worked great.
I had a piped list of filenames in source 'secondary images' in CSV
ie. 527014-2.jpg|527014-3.jpg
Applied the Explode plugin then applied the Rewrite plugin (patched) with replacement pattern "public://import_photos/[brand]/[secondary images]" and all image paths were replaced succesfully in multivalue field, even rows that only had one value before the explode plugin.
Because I made the changes manually, I'm not sure the patch applies cleanly though. I would change the status to 'Needs Review' at least, but I believe my test proves that it works.
Comment #19
elpino CreditAttribution: elpino as a volunteer commentedSpoke to soon,
caught the following warning in watchdog log
Don't know if that is related to #17 #1461308-17: Enabled "multi: loop" for the rewrite plugin, but not likely because my test didn't have NULL values...
Comment #20
4kant CreditAttribution: 4kant commentedI had a task very similar to #18.
For rewriting the path to the image I used the relative path "sites/files/mydirectory/[value]".
With patch #1 everything worked fine. No errors or warnings in watchdog.
Comment #21
NWOM CreditAttribution: NWOM commentedHere is a re-roll of #13 with the change mentioned in #17. Leaving at needs work, since tests are needed.
Comment #22
NWOM CreditAttribution: NWOM commentedComment #23
NWOM CreditAttribution: NWOM commentedAfter applying #22, I Immediately get a WSOD on the Feeds tamper screen of an existing import. This happens with #13 as well.
Comment #24
firfin CreditAttribution: firfin commentedThe WSOD was caused by some overzealous copy pasting I think. The variable
$source
was defined twice in the callbacks of the urlencode and urldecode tampers.Fixed this and made a patch. It is working flawlessly for me now. Used this patch to get multi-valued XML source into a multivalued entityreference using a rewrite. Let's see what the testbot says....
Comment #25
zkrebs CreditAttribution: zkrebs commentedI used #24 successfully yesterday to import multiple taxonomy terms needing hierarchy so I could rewrite parent>> to each term during import.
It applied OK to 7.x-1.2
Comment #26
zkrebs CreditAttribution: zkrebs commentedComment #27
reszliI can also confirm this works