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;
  }
CommentFileSizeAuthor
#1 feeds.code_.2118439-1.patch492 bytesJohnny vd Laar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Johnny vd Laar’s picture

FileSize
492 bytes

Attached is a patch that should fix this.

Johnny vd Laar’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, feeds.code_.2118439-1.patch, failed testing.

MegaChriz’s picture

Some 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.

twistor’s picture

If 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.

MegaChriz’s picture

Issue summary: View changes
Status: Needs work » Closed (fixed)

The 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/2301993
Closing this issue.