Check if the field is empty, if it is then use another field(s) value or even a default value.
Rewrite plugin has the flexibility to use multiple replacement patters, custom string, or a mix of both. But it was lacking the conditional to do the rewrite only if the field values is empty or it is not present in the source.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | rewrite_value_only_if_empty-2632056-10.patch | 1.5 KB | blanca.esqueda |
Comments
Comment #2
blanca.esqueda commentedRewrite only if empty plugin patch
Comment #3
blanca.esqueda commentedComment #4
drupalaar commentedThanks! Lifesaver!Too bad it looks good, but does not work for me :-(
Comment #5
blanca.esqueda commented@drupalar, why is not working?
Did you have an issue applying the patch? Did you check the checkbox option to do the replace only if the field is empty?
Comment #6
dobe commentedI like the idea. I am needing this in my install and not ready to get the feeds tamper php module out. I however am not satisfied with the logic in the patch in #2
I think it would be cleaner if we just wrapped the field in an if statement
Don't have time to reroll this patch. Will do when I have a moment.
Comment #7
drupalaar commentedI checked the option "only if empty", but the rewrite is done on all imported nodes.
Comment #8
dobe commented@drupalaar does this patch work? Or were you commenting on #5?
Comment #9
hartsak commentedThe patch in #8 worked for me. Thanks!
My use case was a feeds user importer in which the source material has a lot of empty email addresses. I used the rewrite tamper plugin with patch #8 and I was able to generate a unique email address using tokens only if their email was empty. Nice!
Comment #10
blanca.esqueda commentedHi @Dove,
You right, the patch needed some re-work on the logic.
But I think it would be more cleaner to have the if statement even before the foreach or anything else is done on the feeds_tamper_rewrite_callback.
It doesn't make sense to have the $trans array created and filled if it is not gonna be used.
Attached is the new patch.
@hartsak If you review it and it works maybe you can set the status as reviewed by the community.
Thanks!
Comment #11
hartsak commentedPatch #10 works fine for me! Thanks! I tried it again with email field.
Comment #12
jimmynash commentedJust chiming in. Patch in #10 worked for me as well.
Thanks!
Comment #13
Collins405 commentedThis is awesome! Lets get this committed!
Comment #14
matthieu_collet commentedVery usefull, thank you !
Comment #15
linl commentedThanks! +1 to RTBC. Patch in #10 works well for me. Similar use case to #9, replacing empty email addresses.
Comment #16
agerard commentedThanks! This was a lifesaver (or at least, brain-saver!). Hope it will be incorporated soon.
Comment #17
efrainhI needed this too! Thank you!
Comment #18
kurt.j commentedPatch in #10 worked for my situation. Thanks Blanca.Esqueda!
Comment #19
steva1982 commentedGreat patch! I hope it will be committed in a stable release.
Comment #20
megachrizIt would be great if this would have automated tests.
Comment #21
nwom commentedSetting to Needs Work as indicated in #20.
Comment #22
anybodyThank you very much for this great feature. #10 works well!
Comment #23
proweb.ua commented#10 works
Comment #24
kopeboyPlease include this in a Drupal 10 release!
Relevant issue already exists: https://www.drupal.org/project/feeds_tamper/issues/3324724
Comment #25
kopeboyComment #26
kopeboyComment #27
kopeboyComment #28
anybody@kopeboy see #20. Still needs tests. If someone finishes them, this can be reviewed and RTBC'd afterward. Thanks!