I have a content type with a text list field with checkboxes / radios widget in it.

CSV import seems to work well: I set the value of the field in CSV and after import I can see the value at the node page. However if I edit an imported node of that type, I see that none of the checkboxes selected.

Possible related issue(?): #1080312: Feeds mapping does not recognize text fields using list widget

I still have not try it with the latest dev version, but I'll give it a try and report my experiences.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thamas’s picture

Tested it with the latest dev version (2012-Feb-09) but had no success.

MegaChriz’s picture

Title: Name of item imported, but item not selected in list field » Import using label of list field succeeds, but item not selected in list field
Component: Feeds Import » Code
Category: Bug report » Support request
Issue summary: View changes

Tested and it appears to still be an issue. When you import into a list text field using the label of the field, that data gets imported, but on the edit form there is no item selected.
With the patch from #2379631: field_attach_validate() must be called before programmatic entity saves the item in question isn't imported, but fails on the error "List Text: illegal value."

Currently, Feeds only supports importing into list text fields using the keys of the field.

For example, given the following allowed values:

a|Item A
b|Item B
c|Item C

Feeds only imports correctly when the source is "a", "b" or "c" (keys used in the list field), but not when the source is "Item A", "Item B" or "Item C" (labels used in the list field).

le72’s picture

So what to do if source CSV contain "Item A", "Item B" or "Item C"?

MegaChriz’s picture

@le72
Changes should be made in feeds/mappers/list.inc, feeds/mappers/number.inc and feeds/mappers/text.inc to add support for importing items by label. To do this, changes should be made each target callback for a list field. These target callbacks are number_feeds_set_target(), list_feeds_set_boolean_target() and text_feeds_set_target(). The following changes need to be made in these functions:

  1. There should be check if the field in question is a list field.
  2. There should be check for the allowed values for the field in question.
  3. If there are allowed values defined, check the provided value against the keys of these.
  4. If the provided key is found, importing of the value may proceed without transformations.
  5. If the provided value does not match any of the keys of the allowed values list, the labels of these should be checked.
  6. If the provided value matches to one of the labels on the allowed values list, the corresponding key should be saved on the field instead.
MegaChriz’s picture

MegaChriz’s picture

Category: Support request » Feature request
brockfanning’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Status: Active » Needs review
FileSize
4.04 KB

Here's my attempt to add this feature.

m.stenta’s picture

Thanks @brockfanning for the patch!

In my case, I am providing the list of allowed values for my fields programatically, using the "allowed_values_function" field setting. In these cases, the "allowed_values" setting is empty, so the patch doesn't help. I modified your patch slightly so that it would also work with that setting. I used the list_allowed_values() function provided by the List module (which, along with the Options module are what provide the "allowed_values" setting). This function checks both settings and builds an array accordingly.

It's working great for me! I would RTBC this, but because I changed it someone else should review.

m.stenta’s picture

One thing I'm noticing however: I am not seeing the error described by @MegaChriz in comment #2 above when I add a non-allowed value in my CSV import file. I am using 7.x-2.0-beta4, so I do have the new validation logic added by #2379631: field_attach_validate() must be called before programmatic entity saves. I will debug a bit to see if I can figure out why.

m.stenta’s picture

Ok, I remember why I'm not seeing the validation error - it's because the field I am importing to is within a Field Collection. I discovered this issue a few months back and commented on it in the Field Collection feature request for Feeds integration: https://www.drupal.org/project/field_collection/issues/1063434

So that's probably an issue in the Field Collection module, not in Feeds. Disregard for now. :-)

MegaChriz’s picture

Issue tags: +Needs tests

@m.stenta
It would be great if we have an automated test for this feature. Do you want to create one?

vchen’s picture

I tested patch8 and it still doesn't work for me. I used the key, the label, even tried numbers where the first pair = 0, etc.

Nothing imported for that field; it's always blank (no checkboxes were checked).

vchen’s picture

Actually, patch 8 works. I accidentally deleted my importer and had to recreate it again. After I rebuilt the importer and ran another import, the list value populated correctly.

danharper’s picture

I'm looking for this in Drupal8, shall I log a separate issue?

NWOM’s picture

#8 works great! I would love to see it get added to the module. Thanks for everyone's work on this!

Frosty29’s picture

#8 was a great help - thank you! There was one issue I had to solve manually.
My list had
1|Most Junior
2|Junior
3|Middle
4|Senior
5|Most senior
Items with "Most senior" would not import. The feeds log shows it as "Most 4" not valid - i.e. the "senior" had been subsituted already, for the key of 4.