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 have a CSV feed with a column that is mapped to a taxonomy term. It is set to not create new terms. I use the CSV feed to update users and I don't want it to empty fields that are left empty.
This works for normal textfields but taxonomy term columns that are left empty result in emptying the term field.
It is caused by this part of code in the taxonomy.inc file:
function taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping = array()) {
// Allow mapping the string '0' to a term name.
if (empty($terms) && $terms != 0) {
return;
}
I don't think that this if statement can ever evaluate to true? (I'm not sure about all the edge cases tho)
But I think that it should be this:
function taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping = array()) {
// Allow mapping the string '0' to a term name.
if (empty($terms) && $terms !== 0) {
return;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | feeds.code_.2118439-1.patch | 492 bytes | Johnny vd Laar |
Comments
Comment #1
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedAttached is a patch that should fix this.
Comment #2
Johnny vd Laar CreditAttribution: Johnny vd Laar commentedComment #4
MegaChriz CreditAttribution: MegaChriz commentedSome related issues to this issue:
@Johnny vd Laar
You could check if this problem still exists with the latest patch from #2093651: Simplify target callbacks. that touches the same piece of code.
#1668186: Taxonomy terms auto-created with empty name. deals with a related issue, but will not fix the issue here.
Comment #5
twistor CreditAttribution: twistor commentedIf the field is empty in the feed, then it should be empty on the node.
We are intentionally trying to allow 0, or '0' as a term name.
I think you might be suffering from the conclusion of, #1107522: Framework for expected behavior when importing empty/blank values + text field fix.
Comment #6
MegaChriz CreditAttribution: MegaChriz commentedThe latest tests from #1107522: Framework for expected behavior when importing empty/blank values + text field fix prove that mapping
0
to terms work as expected. As twistor says, if you map to a term field, but the source for the term is empty, the target should be emptied as well. See the change record: https://www.drupal.org/node/2301993Closing this issue.